TUNGKAO API docs
API · apple_login

Sign in with Apple

Add a 'Sign in with Apple' button to your site without registering with Apple yourself. You get: permanent member ID (no name or email in this mode)

🕒 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

https://app.tungkao.com/docs/api/apple_login.md?lang=en
https://api.tungkao.com/changelog/apple_login.json

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

Copy + open in: pressing an AI button copies the prompt automatically — if the chat box is empty, just paste

🔑 Key to use

Create a apple_login key in the merchant portal (API keys) and send this header with every request — keys of other services won't work here

Authorization: Bearer $TUNGKAO_KEY

🔗 Your sign-in button link

https://api.tungkao.com/oauth/authorize?client_id=<CLIENT_ID>&redirect_uri=https%3A%2F%2Fyourshop.com%2Fauth%2Fcallback&state=<RANDOM>

🛡️ Everything ends on tungkao: users sign in with Apple 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: permanent member ID (no name or email in this mode)

📋 How it works

  1. Create a key for the provider, then on 'Sign-in members' set your site name and redirect URI (https, exact match).
  2. 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).
  3. The user returns to redirect_uri?code=…&state=… → check state → your server calls POST /v1/login/token within 2 minutes.
  4. 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"}'
GET/v1/login/users?limit=50
curl -X GET https://api.tungkao.com/v1/login/users?limit=50 \
  -H "Authorization: Bearer $TUNGKAO_KEY"

📖 Summary: using sign-in keys on several sites

CaseKey setting (API Keys page)Result
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 accountsBoth keys: SeparateThe same person gets a different user ID on each key
2 sister sites sharing membersBoth keys: Group AA member has the same user ID on both sites ✅
2 unrelated sites that must not link membersBoth keys: SeparateDifferent user IDs, so the sites can't link their members ✅
A Google key and a LINE key (different providers)Any settingAlways different user IDs — they are different provider accounts
A key that already has sign-ins needs a different groupNot 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);
ProviderServiceYou get
Googlegoogle_loginname, verified email, photo
LINEline_loginname, photo, email if the user agrees
Facebookfacebook_loginname, photo, email
TikToktiktok_logindisplay name, avatar (no email)
Discorddiscord_loginname, avatar, email
Telegramtelegram_loginname, username, photo
X (Twitter)x_loginname, username, photo
Microsoftmicrosoft_loginname, email (Hotmail/Outlook)
GitHubgithub_loginname, email, avatar
Appleapple_loginpermanent member ID (no name or email in this mode)
Steamsteam_loginname, avatar and SteamID (no email)
Twitchtwitch_loginname, email, avatar
LinkedInlinkedin_loginname, email, photo
Kakaokakao_loginname, photo (email once Kakao approves it)
NAVERnaver_loginname, email, photo
Zalozalo_loginname, photo (no email)
Spotifyspotify_loginname, email, photo
Redditreddit_loginusername, avatar (no email)
GitLabgitlab_loginname, email, avatar
Robloxroblox_loginname, avatar (no email)
Epic Gamesepicgames_logindisplay name (no email)
Yahooyahoo_loginname, email, photo
Slackslack_loginname, email, photo
Amazonamazon_loginname, email

📚 Usage examples

Example 1

A “Sign in with Apple” button on your site

Situation: A visitor taps Sign in with Apple 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 Apple 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"
}
Sample response
{
  "success": true,
  "data": {
    "user": "7F3K9QX2-yourshopcom",
    "provider": "apple",
    "name": "Somchai",
    "is_new_user": true
  }
}

➡️ Use user as the member id in your database (stable per person)

Example 3

A returning user signs in

Situation: The same person signs in with Apple again

Sample response
{
  "success": true,
  "data": {
    "user": "7F3K9QX2-yourshopcom",
    "is_new_user": false,
    "login_count": 5
  }
}

➡️ Same user every time → look up the member and sign them in

Example 4

One site, two Apple 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 Apple screen

➡️ Returns to redirect_uri with error instead of code; show a retry button

💡 More

📜 Update history of this API

  1. Added Thailand 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
  2. Added Thailand time (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)
  3. Added Thailand time (UTC+07:00)
    API update announcements by webhook: new api.update event (opt in per key on the key card; off by default)
  4. Added Thailand 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)
  5. Added Thailand time (UTC+07:00)
    GET /status: per-service API status 🟢 normal / 🟠 high traffic / 🔴 minor delays (no key needed)
  6. Added Thailand time (UTC+07:00)
    Key on/off switch with status-change time + one key per service per website
  7. Improved Thailand time (UTC+07:00)
    API v1 frozen (additive only) + X-Tungkao-Api-Version header + 12-month deprecation notices
  8. Docs Thailand time (UTC+07:00)
    Per-API docs pages with AI links (ChatGPT / Claude / Gemini / Grok) in 10 languages
  9. Security Thailand time (UTC+07:00)
    Domain verification per API key (1 key = 1 site) — existing keys keep working
  10. Added Thailand time (UTC+07:00)
    Optional HMAC request signing — nothing changes unless you turn it on
  11. Added Thailand time (UTC+07:00)
    API key lifetimes, expiry warnings and renewal — the key string never changes
  12. Added Thailand time (UTC+07:00)
    Test-mode keys (simulated, free) for every service

✅ Your existing code keeps working

🛡️ Stability promise: integrate once, keep working

🚦 System status (GET /status)

Check any time whether the API is healthy — no key needed

GET https://api.tungkao.com/status

curl https://api.tungkao.com/status
{
  "success": true,
  "data": {
    "status": "ok",
    "services": [
      { "id": "slip_verify", "status": "ok", "routes": ["ok", "ok", "busy"] },
      { "id": "slip_deposit", "status": "ok", "routes": ["ok", "ok", "busy"] },
      { "id": "login", "status": "ok" },
      { "id": "telegram", "status": "ok" },
      { "id": "discord", "status": "ok" },
      { "id": "email", "status": "busy" },
      { "id": "crypto", "status": "ok" },
      { "id": "core", "status": "ok" }
    ],
    "paused": [],
    "updated_at": "2026-11-14T12:00:00.000Z"
  }
}

🏷️ TUNGKAO attribution requirement

Powered by TUNGKAO