Add a 'Sign in with Microsoft' button to your site without registering with Microsoft yourself. You get: name, email (Hotmail/Outlook)
🕒 Last updated: Thailand time (UTC+07:00) · ✅ Your existing code keeps working
🤖 Let an AI write the integration
Copy this link for an AI to read (the whole API as Markdown), or press a button: the prompt is copied and the AI opens — paste it and tell it your language/framework
This link returns this API's updates as JSON (no key, any origin). Have your admin page show it as an “Update announcements” box and flag “New” when last_updated changes
🛡️ Everything ends on tungkao: users sign in with Microsoft and always come back to tungkao first. We send them to your link only after a real sign-in (or a cancel during sign-in) — anyone opening links directly just sees a tungkao page and goes nowhere. Set 🌐 your domain (verify it) and ↩️ the return link in 'Members'.
You get: name, email (Hotmail/Outlook)
📋 How it works
Create a key for the provider, then on 'Sign-in members' set your site name and redirect URI (https, exact match).
Your sign-in button sends the user to /oauth/authorize with client_id (the key id), redirect_uri and state (fresh random, kept in the session).
The user returns to redirect_uri?code=…&state=… → check state → your server calls POST /v1/login/token within 2 minutes.
Use data.user (e.g. 7F3K9QX2-yourshopcom) as the member id — the same person always gets the same id.
📡 API calls + code examples
POST/v1/login/token
curl -X POST https://api.tungkao.com/v1/login/token \
-H "Authorization: Bearer $TUNGKAO_KEY" \
-H "Content-Type: application/json" \
-d '{"code":"from the redirect","redirect_uri":"https://yourshop.com/auth/callback"}'
// Node.js 18+ (nothing to install)
const res = await fetch("https://api.tungkao.com/v1/login/token", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.TUNGKAO_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
"code": "from the redirect",
"redirect_uri": "https://yourshop.com/auth/callback"
}),
});
const data = await res.json();
console.log(data);
One site, 2 keys of the same provider (e.g. website + app, both Google)
Both keys: Combined (default)
The same person gets the same user ID in both ✅
One site, 2 keys of the same provider, counted as separate accounts
Both keys: Separate
The same person gets a different user ID on each key
2 sister sites sharing members
Both keys: Group A
A member has the same user ID on both sites ✅
2 unrelated sites that must not link members
Both keys: Separate
Different user IDs, so the sites can't link their members ✅
A Google key and a LINE key (different providers)
Any setting
Always different user IDs — they are different provider accounts
A key that already has sign-ins needs a different group
Not allowed (locked 🔒)
Create a new key in the wanted group, so member IDs on your site never change
Set it on the “Sign-in user IDs between keys” card on the API Keys page before go-live (new keys default: Combined). Several keys may use the same domain.
Complete example (button + callback + code exchange)
// npm i express express-session
import express from "express";
import session from "express-session";
import crypto from "node:crypto";
const KEY = process.env.TUNGKAO_KEY; // API key (tk_live_…) server-side only
const CLIENT_ID = process.env.TUNGKAO_CLIENT_ID; // the key id (shown in the portal), not a secret
const REDIRECT = "https://yourshop.com/auth/callback"; // must match the registered URL exactly
const app = express();
app.use(session({ secret: process.env.SESSION_SECRET, resave: false, saveUninitialized: false, cookie: { secure: true, sameSite: "lax" } }));
// 1) your "Sign in" button links here
app.get("/auth/login", (req, res) => {
req.session.state = crypto.randomBytes(24).toString("base64url");
const u = new URL("https://api.tungkao.com/oauth/authorize");
u.search = new URLSearchParams({ client_id: CLIENT_ID, redirect_uri: REDIRECT, state: req.session.state });
res.redirect(u);
});
// 2) the user comes back with a code
app.get("/auth/callback", async (req, res) => {
if (!req.query.state || req.query.state !== req.session.state) return res.status(400).send("state mismatch");
delete req.session.state;
if (req.query.error) return res.redirect("/login?cancelled=1");
// 3) exchange the code for the user (within 2 minutes)
const r = await fetch("https://api.tungkao.com/v1/login/token", {
method: "POST",
headers: { Authorization: `Bearer ${KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({ code: req.query.code, redirect_uri: REDIRECT }),
});
const j = await r.json();
if (!j.success) return res.status(400).send(j.error.message);
req.session.user = j.data; // j.data.user = permanent member id, e.g. 7F3K9QX2-yourshopcom
res.redirect("/");
});
app.listen(3000);
<?php
// login.php — your "Sign in" button links to this file
session_start();
$CLIENT_ID = getenv("TUNGKAO_CLIENT_ID");
$REDIRECT = "https://yourshop.com/callback.php";
$_SESSION["state"] = bin2hex(random_bytes(24));
header("Location: https://api.tungkao.com/oauth/authorize?" . http_build_query([
"client_id" => $CLIENT_ID, "redirect_uri" => $REDIRECT, "state" => $_SESSION["state"],
]));
<?php
// callback.php — the user comes back here
session_start();
$REDIRECT = "https://yourshop.com/callback.php";
if (empty($_GET["state"]) || !hash_equals($_SESSION["state"] ?? "", $_GET["state"])) { http_response_code(400); exit("state mismatch"); }
unset($_SESSION["state"]);
if (!empty($_GET["error"])) { header("Location: /login.php?cancelled=1"); exit; }
$ch = curl_init("https://api.tungkao.com/v1/login/token");
curl_setopt_array($ch, [
CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer " . getenv("TUNGKAO_KEY"), "Content-Type: application/json"],
CURLOPT_POSTFIELDS => json_encode(["code" => $_GET["code"], "redirect_uri" => $REDIRECT]),
]);
$j = json_decode(curl_exec($ch), true);
if (!$j["success"]) { http_response_code(400); exit($j["error"]["message"]); }
$_SESSION["user"] = $j["data"]; // $j["data"]["user"] = permanent member id
header("Location: /");
# pip install flask requests
import os, secrets, requests
from urllib.parse import urlencode
from flask import Flask, session, request, redirect, abort
app = Flask(__name__)
app.secret_key = os.environ["SESSION_SECRET"]
KEY = os.environ["TUNGKAO_KEY"]
CLIENT_ID = os.environ["TUNGKAO_CLIENT_ID"]
REDIRECT = "https://yourshop.com/auth/callback"
@app.get("/auth/login")
def login():
session["state"] = secrets.token_urlsafe(24)
return redirect("https://api.tungkao.com/oauth/authorize?" + urlencode({"client_id": CLIENT_ID, "redirect_uri": REDIRECT, "state": session["state"]}))
@app.get("/auth/callback")
def callback():
if not request.args.get("state") or not secrets.compare_digest(request.args["state"], session.pop("state", "")):
abort(400)
if request.args.get("error"):
return redirect("/login?cancelled=1")
r = requests.post("https://api.tungkao.com/v1/login/token", headers={"Authorization": f"Bearer {KEY}"},
json={"code": request.args["code"], "redirect_uri": REDIRECT}, timeout=30).json()
if not r["success"]:
abort(400, r["error"]["message"])
session["user"] = r["data"] # r["data"]["user"] = permanent member id
return redirect("/")
Provider
Service
You get
Google
google_login
name, verified email, photo
LINE
line_login
name, photo, email if the user agrees
Facebook
facebook_login
name, photo, email
TikTok
tiktok_login
display name, avatar (no email)
Discord
discord_login
name, avatar, email
Telegram
telegram_login
name, username, photo
X (Twitter)
x_login
name, username, photo
Microsoft
microsoft_login
name, email (Hotmail/Outlook)
GitHub
github_login
name, email, avatar
Apple
apple_login
permanent member ID (no name or email in this mode)
Steam
steam_login
name, avatar and SteamID (no email)
Twitch
twitch_login
name, email, avatar
LinkedIn
linkedin_login
name, email, photo
Kakao
kakao_login
name, photo (email once Kakao approves it)
NAVER
naver_login
name, email, photo
Zalo
zalo_login
name, photo (no email)
Spotify
spotify_login
name, email, photo
Reddit
reddit_login
username, avatar (no email)
GitLab
gitlab_login
name, email, avatar
Roblox
roblox_login
name, avatar (no email)
Epic Games
epicgames_login
display name (no email)
Yahoo
yahoo_login
name, email, photo
Slack
slack_login
name, email, photo
Amazon
amazon_login
name, email
📚 Usage examples
Example 1
A “Sign in with Microsoft” button on your site
Situation: A visitor taps Sign in with Microsoft on your site
Request
GET /oauth/authorize?client_id=<CLIENT_ID>&redirect_uri=https://yourshop.com/auth/callback&state=xyz
➡️ The user signs in with Microsoft and returns to redirect_uri with a code and the same state
Example 2
Exchange the code for the user (server side)
Situation: Your server receives the code on the callback page (exchange within 2 minutes)
Request
POST /v1/login/token
{
"code": "<code from the callback>",
"redirect_uri": "https://yourshop.com/auth/callback"
}
➡️ Same user every time → look up the member and sign them in
Example 4
One site, two Microsoft keys (website + app)
Situation: Separate keys for website and app, same members
➡️ Keep both keys “Combined” (default) before go-live → same user for the same person. Choose “Separate” to keep them apart
Example 5
List members who signed in
Situation: You want to browse or search members of this key
Request
GET /v1/login/users?q=somchai&limit=50
➡️ Returns members with last sign-in time and count
Example 6
The user cancels during sign-in
Situation: The user cancels on the Microsoft screen
➡️ Returns to redirect_uri with error instead of code; show a retry button
💡 More
User IDs between keys: new keys default to “Combined (whole account)”, so the same person signing in through keys of the same provider in one account gets the same ID. Change it to group A–E or “Separate” on the API Keys page before the first sign-in; after that the group is locked so member IDs never change.
Credits are charged on each successful sign-in plus once per new member — see current prices on the service card.
Test-mode keys allow http://localhost redirect URIs and are free.
Never put the API key in links or pages — /oauth/authorize only needs client_id (the key id), which is public.
📜 Update history of this API
AddedThailand time (UTC+07:00)
Sign-in: choose whether user IDs are combined or separate between keys (whole account / group A–E / separate). New keys default to combined; keys that already have sign-ins stay in their group
AddedThailand time (UTC+07:00)
API update announcements by webhook: new api.update event (opt in per key on the key card; off by default)
AddedThailand time (UTC+07:00)
Mobile sign-in that jumps to the provider app (X, Discord, LINE…): two per-key options — A stay in the same browser (Android, recommended), B the original tab signs in on return (tk-login.js). Desktop is unaffected
AddedThailand time (UTC+07:00)
Ready-made sign-in buttons: /static/tk-login.js restyles your existing buttons with real logos and colours (add data-tk-login)
ImprovedThailand time (UTC+07:00)
A bad sign-in link (client_id / redirect_uri / state) now shows a page with the reason and the fix instead of redirecting home
AddedThailand time (UTC+07:00)
error.user_message: ready-to-show text for end users on outages, no credits or key problems (white-label keys omit tungkao.com)
AddedThailand time (UTC+07:00)
GET /status: per-service API status 🟢 normal / 🟠 high traffic / 🔴 minor delays (no key needed)
AddedThailand time (UTC+07:00)
Key on/off switch with status-change time + one key per service per website
Per-API docs pages with AI links (ChatGPT / Claude / Gemini / Grok) in 10 languages
SecurityThailand time (UTC+07:00)
Domain verification per API key (1 key = 1 site) — existing keys keep working
AddedThailand time (UTC+07:00)
Optional HMAC request signing — nothing changes unless you turn it on
AddedThailand time (UTC+07:00)
API key lifetimes, expiry warnings and renewal — the key string never changes
AddedThailand time (UTC+07:00)
Test-mode keys (simulated, free) for every service
✅ Your existing code keeps working
🛡️ Stability promise: integrate once, keep working
API /v1 is frozen: nothing is removed, renamed or retyped — only new fields or endpoints are added. Automated contract tests block any deploy that would break existing code.
When providers (banks, LINE, Google, Facebook, TikTok, Discord, Telegram, blockchains) change, we adapt on our servers — your code stays the same. Slip checks fail over across 3 providers automatically.
Write future-proof code: ignore unknown fields, branch on error.code (not message text), and treat an unknown new status as “not passed / pending”.
If something ever must be retired, we announce it at least 12 months ahead via Deprecation / Sunset headers on every response, email and webhook — the old behaviour keeps working until then.
Every response carries an X-Tungkao-Api-Version header with the version and latest revision date. Full history: /changelog.json
🚦 System status (GET /status)
Check any time whether the API is healthy — no key needed
GET https://api.tungkao.com/status
🟢 ok = normal
🟠 busy = high traffic
🔴 slow = minor delays
Measured from real requests over the last 5 minutes, per service (services[]). Slip verification and slip deposits are measured across every backup provider, with each route's state in routes[]
No API key; callable from browsers (CORS open); cached 15 s — poll at most once a minute
On busy/slow, raise your timeout to 15–20 s and retry with the same Idempotency-Key — you are never charged twice
paused[] lists service codes TUNGKAO has switched off for now (e.g. line_login) — grey that button out and show “System temporarily unavailable” (API calls return 503 SERVICE_PAUSED, nothing charged)
Every page or screen that uses a TUNGKAO service (slip check, deposits, crypto, login, notifications) must show visible “Powered by TUNGKAO” or “Secured by TUNGKAO” text linking to https://tungkao.com
Place it near the feature — under the sign-in button, under the slip upload, or on the payment page. Do not hide it, blend it into the background or make it unreadably small
Buttons from the “Login buttons” page include the credit automatically, and the hosted TUNGKAO sign-in page shows it itself
Example: <a href="https://tungkao.com" target="_blank" rel="noopener">Powered by TUNGKAO</a>
To remove the credit, buy the White-label add-on for that key on the API keys page in the portal (30 days at a time)