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.
ຕົວຢ່າງຄົບລະບົບ (ປຸ່ມ + ຮັບກັບ + ແລກ code)
// 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("/")
ຄ່າຍ
ບໍລິການ
ໄດ້ຂໍ້ມູນ
Google
google_login
ຊື່ ອີເມວ (ຢືນຢັນແລ້ວ) ຮູບ
LINE
line_login
ຊື່ ຮູບ ອີເມວ (ຖ້າຍິນຍອມ)
Facebook
facebook_login
ຊື່ ຮູບ ອີເມວ
TikTok
tiktok_login
ຊື່ທີ່ສະແດງ ຮູບ (ບໍ່ມີອີເມວ)
Discord
discord_login
ຊື່ ຮູບ ອີເມວ
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
📚 ຕົວຢ່າງການໃຊ້ງານ
ຕົວຢ່າງທີ 1
A “Sign in with Twitch” button on your site
ສະຖານະການ: A visitor taps Sign in with Twitch on your site
ສົ່ງຄຳຂໍ
GET /oauth/authorize?client_id=<CLIENT_ID>&redirect_uri=https://yourshop.com/auth/callback&state=xyz
➡️ The user signs in with Twitch and returns to redirect_uri with a code and the same state
ຕົວຢ່າງທີ 2
Exchange the code for the user (server side)
ສະຖານະການ: Your server receives the code on the callback page (exchange within 2 minutes)
ສົ່ງຄຳຂໍ
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
ຕົວຢ່າງທີ 4
One site, two Twitch keys (website + app)
ສະຖານະການ: 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
ຕົວຢ່າງທີ 5
List members who signed in
ສະຖານະການ: You want to browse or search members of this key
ສົ່ງຄຳຂໍ
GET /v1/login/users?q=somchai&limit=50
➡️ Returns members with last sign-in time and count
ຕົວຢ່າງທີ 6
The user cancels during sign-in
ສະຖານະການ: The user cancels on the Twitch screen
➡️ Returns to redirect_uri with error instead of code; show a retry button
💡 ເພີ່ມເຕີມ
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.
key ໂໝດ test ໃຊ້ລິ້ງກັບ http://localhost ໄດ້ ແລະ ບໍ່ຄິດເຄຣດິດ
ຫ້າມໃສ່ API key ໃນລິ້ງ ຫຼື ໜ້າເວັບ — /oauth/authorize ໃຊ້ແຕ່ client_id (id ຂອງ key) ທີ່ເປີດເຜີຍໄດ້
📜 ປະຫວັດການອັບເດດຂອງ API ນີ້
ເພີ່ມເວລາປະເທດໄທ (UTC+07:00)
🖼️ Show your own logo on the sign-in page, per key (50×50, auto-cropped and resized). Billed monthly: buy 1–11 months or 1 / 2 / 3 years. Hiding the credit now offers the same periods.
ປັບປຸງເວລາປະເທດໄທ (UTC+07:00)
🌐 The sign-in page and the phone-model sign-in help now support all 10 API languages (th, en, lo, my, zh-CN, ko, ja, vi, km, id), picked from the device language or &lang= on the sign-in link, with a language switcher at the bottom
ປັບປຸງເວລາປະເທດໄທ (UTC+07:00)
📱 The sign-in help page now names the visitor's exact phone model (e.g. Galaxy S24 Ultra), adds model search, and refreshes the Android model list daily from Google Play — new models get a “New” badge
ເພີ່ມເວລາປະເທດໄທ (UTC+07:00)
📱 Step-by-step “sign-in doesn't continue” help by phone brand and model (iPhone, iPad, Samsung, Huawei, HONOR, Xiaomi, OPPO, vivo, realme, OnePlus, Pixel, other Android), with the brand guessed from the device and a link from the sign-in page
ເພີ່ມເວລາປະເທດໄທ (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
ເພີ່ມເວລາປະເທດໄທ (UTC+07:00)
15 new sign-in providers: Apple, Steam, Twitch, LinkedIn, Kakao, NAVER, Zalo, Spotify, Reddit, GitLab, Roblox, Epic Games, Yahoo, Slack, Amazon. Same /oauth/authorize link and POST /v1/login/token as every existing provider (each one goes on sale when ready; see the services page)
ເພີ່ມເວລາປະເທດໄທ (UTC+07:00)
API update announcements by webhook: new api.update event (opt in per key on the key card; off by default)
ເພີ່ມເວລາປະເທດໄທ (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)
ເພີ່ມເວລາປະເທດໄທ (UTC+07:00)
GET /status: ສະຖານະ API ແຍກທຸກບໍລິການ (ບໍ່ຕ້ອງໃຊ້ key)