Theo điều khoản, trang dùng dịch vụ phải hiển thị “Powered by TUNGKAO” (hoặc “Secured by TUNGKAO” cho đăng nhập/thanh toán) liên kết tới https://tungkao.com
Liên kết này trả về các cập nhật của API dưới dạng JSON (không cần key, mọi nguồn). Hãy hiển thị trong trang quản trị như hộp “Thông báo cập nhật” và gắn “Mới” khi last_updated thay đổi
🛡️ Mọi bước kết thúc tại tungkao: người dùng đăng nhập với Roblox rồi luôn quay về tungkao trước. Chỉ khi đăng nhập thật sự thành công (hoặc hủy trong lúc đăng nhập) mới chuyển tới liên kết của bạn — ai mở liên kết trực tiếp chỉ thấy trang tungkao. Đặt 🌐 tên miền (xác minh) và ↩️ liên kết quay về ở 'Thành viên'.
Bạn nhận được: name, avatar (no email)
📋 Các bước
Tạo key cho nhà cung cấp, rồi ở 'Thành viên đăng nhập' đặt tên site và redirect URI (https, khớp chính xác).
Nút đăng nhập đưa người dùng tới /oauth/authorize kèm client_id (ID key), redirect_uri và state (ngẫu nhiên mới, lưu trong session).
Người dùng quay về redirect_uri?code=…&state=… → kiểm tra state → máy chủ gọi POST /v1/login/token trong vòng 2 phút.
Dùng data.user (vd 7F3K9QX2-yourshopcom) làm ID thành viên — cùng một người luôn cùng một ID.
📡 Gọi API + mã mẫu
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.
Ví dụ đầy đủ (nút + callback + đổi 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("/")
Nhà cung cấp
Dịch vụ
Bạn nhận được
Google
google_login
tên, email đã xác minh, ảnh
LINE
line_login
tên, ảnh, email nếu người dùng đồng ý
Facebook
facebook_login
tên, ảnh, email
TikTok
tiktok_login
tên hiển thị, ảnh đại diện (không email)
Discord
discord_login
tên, ảnh đại diện, 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
📚 Ví dụ sử dụng
Ví dụ 1
A “Sign in with Roblox” button on your site
Tình huống: A visitor taps Sign in with Roblox on your site
Yêu cầu
GET /oauth/authorize?client_id=<CLIENT_ID>&redirect_uri=https://yourshop.com/auth/callback&state=xyz
➡️ The user signs in with Roblox and returns to redirect_uri with a code and the same state
Ví dụ 2
Exchange the code for the user (server side)
Tình huống: Your server receives the code on the callback page (exchange within 2 minutes)
Yêu cầu
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
Ví dụ 4
One site, two Roblox keys (website + app)
Tình huống: 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
Ví dụ 5
List members who signed in
Tình huống: You want to browse or search members of this key
Yêu cầu
GET /v1/login/users?q=somchai&limit=50
➡️ Returns members with last sign-in time and count
Ví dụ 6
The user cancels during sign-in
Tình huống: The user cancels on the Roblox screen
➡️ Returns to redirect_uri with error instead of code; show a retry button
💡 Thêm
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.
Tính phí mỗi lần đăng nhập thành công và một lần cho mỗi thành viên mới — xem giá hiện tại trên thẻ dịch vụ.
Key chế độ test cho phép redirect http://localhost và miễn phí.
Không bao giờ đặt API key trong link hay trang — /oauth/authorize chỉ cần client_id (ID key) công khai.
📜 Lịch sử cập nhật API này
Bổ sungGiờ Thái Lan (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.
Cải tiếnGiờ Thái Lan (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
Cải tiếnGiờ Thái Lan (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
Bổ sungGiờ Thái Lan (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
Bổ sungGiờ Thái Lan (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
Bổ sungGiờ Thái Lan (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)
Bổ sungGiờ Thái Lan (UTC+07:00)
API update announcements by webhook: new api.update event (opt in per key on the key card; off by default)
Bổ sungGiờ Thái Lan (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)
Bổ sungGiờ Thái Lan (UTC+07:00)
GET /status: trạng thái API theo từng dịch vụ (không cần key)
Bổ sungGiờ Thái Lan (UTC+07:00)
Công tắc bật/tắt key kèm thời điểm đổi trạng thái + mỗi website 1 key cho mỗi dịch vụ
Cải tiếnGiờ Thái Lan (UTC+07:00)
Khóa vĩnh viễn API v1 (chỉ bổ sung) + header X-Tungkao-Api-Version + báo ngừng trước 12 tháng
Tài liệuGiờ Thái Lan (UTC+07:00)
Trang tài liệu riêng cho từng API kèm liên kết AI (10 ngôn ngữ)
Bảo mậtGiờ Thái Lan (UTC+07:00)
Xác minh tên miền cho từng API key (1 key = 1 site) — key cũ vẫn hoạt động
Bổ sungGiờ Thái Lan (UTC+07:00)
Ký yêu cầu HMAC tùy chọn — không bật thì không đổi gì
Bổ sungGiờ Thái Lan (UTC+07:00)
Thời hạn API key, nhắc hết hạn và gia hạn — chuỗi key không đổi
Bổ sungGiờ Thái Lan (UTC+07:00)
Key chế độ test (mô phỏng, miễn phí) cho mọi dịch vụ
✅ Mã cũ vẫn chạy, không cần sửa
🛡️ Cam kết ổn định: tích hợp một lần, chạy mãi
API /v1 được khóa vĩnh viễn: không xóa, không đổi tên, không đổi kiểu — chỉ thêm trường hoặc endpoint mới. Kiểm thử hợp đồng tự động chặn mọi lần triển khai làm hỏng mã cũ.
Khi nhà cung cấp (ngân hàng, LINE, Google, Facebook, TikTok, Discord, Telegram, blockchain) thay đổi, chúng tôi xử lý ở máy chủ — mã của bạn giữ nguyên. Kiểm tra biên lai tự chuyển dự phòng giữa 3 nhà cung cấp.
Viết mã bền vững: bỏ qua trường lạ, phân nhánh theo error.code (không theo câu chữ), coi status mới chưa biết là “chưa đạt/đang chờ”.
Nếu có gì phải ngừng, chúng tôi báo trước ít nhất 12 tháng qua header Deprecation / Sunset trong mọi phản hồi, email và webhook — cách cũ vẫn chạy tới ngày đó.
Mọi phản hồi có header X-Tungkao-Api-Version ghi phiên bản và ngày sửa đổi mới nhất. Toàn bộ lịch sử: /changelog.json
🚦 Trạng thái hệ thống (GET /status)
Kiểm tra API có bình thường không bất cứ lúc nào — không cần key
GET https://api.tungkao.com/status
🟢 ok = bình thường
🟠 busy = lưu lượng cao
🔴 slow = hơi chậm
Đo từ yêu cầu thật trong 5 phút gần nhất, theo từng dịch vụ (services[]). Xác minh/nạp bằng biên lai được đo trên mọi nhà cung cấp dự phòng, trạng thái từng tuyến trong routes[]
Không cần API key, gọi được từ trình duyệt (mở CORS), cache 15 giây — nên kiểm tra tối đa 1 lần/phút
Khi busy/slow, tăng timeout lên 15–20 giây và thử lại với cùng Idempotency-Key — không bị tính phí hai lần