Authorization Code Flow
End-to-end OAuth 2.1 authorization handshake linking MCP client registration, Discord identity verification, server-scoped consent, and code exchange.
Client Identification: CIMD and RFC 7591 DCR
Before calling /oauth/authorize, an MCP client identifies itself using either a Client ID Metadata Document (CIMD) URL or a client_id obtained via Dynamic Client Registration at POST /oauth/register.
- Client ID Metadata Documents (CIMD):: When client_id is an HTTPS URL, Taicket fetches the metadata document using a DNS-rebinding-pinned socket lookup that rejects loopback, RFC1918, link-local, CGNAT, and redirect responses, enforcing a 32 KB body cap and 5-second timeout.
- Dynamic Client Registration (RFC 7591):: Clients without hosted metadata call POST /oauth/register. Taicket validates every redirect_uri against strict scheme and host rules: exact https:// URLs or loopback http://127.0.0.1 / http://localhost URLs only. Wildcards, URL fragments, and non-loopback http:// URIs are rejected.
POST /oauth/register HTTP/1.1
Host: mcp.taicket.xyz
Content-Type: application/json
{
"client_name": "Example MCP Host",
"redirect_uris": [
"http://127.0.0.1:49152/oauth/callback"
],
"grant_types": [
"authorization_code",
"refresh_token"
],
"response_types": [
"code"
],
"token_endpoint_auth_method": "none"
}{
"client_id": "dcr_9f4b2a1c8e7d6053a1b2c3d4",
"client_name": "Example MCP Host",
"redirect_uris": [
"http://127.0.0.1:49152/oauth/callback"
],
"grant_types": [
"authorization_code",
"refresh_token"
],
"response_types": [
"code"
],
"token_endpoint_auth_method": "none",
"client_id_issued_at": 1765000000
}Step-by-Step Authorization Sequence
- 1
Client redirects browser to /oauth/authorize
The MCP client opens the user browser to /oauth/authorize with response_type=code, client_id, redirect_uri, scope, state, code_challenge, code_challenge_method=S256, and resource=https://mcp.taicket.xyz/mcp. Taicket validates every parameter, persists a 10-minute McpOAuthTransaction in taicket_mcp, binds it to an HttpOnly SameSite=Lax Secure cookie, and redirects the browser to Discord OAuth2.
Authorization requesthttpGET /oauth/authorize?response_type=code&client_id=dcr_9f4b2a1c8e7d6053a1b2c3d4&redirect_uri=http%3A%2F%2F127.0.0.1%3A49152%2Foauth%2Fcallback&scope=mcp%3Aread%20mcp%3Awrite&state=st_8a1f3e9c&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256&resource=https%3A%2F%2Fmcp.taicket.xyz%2Fmcp HTTP/1.1 Host: mcp.taicket.xyz - 2
User authorizes Discord identity (identify guilds)
Discord prompts the user to sign in and approve the minimal identify and guilds scopes. Upon approval, Discord redirects back to https://mcp.taicket.xyz/oauth/discord/callback with an upstream code and transaction state.
- 3
Taicket verifies transaction and encrypts Discord tokens
The callback verifies both the state parameter and the SHA-256 hash of the HttpOnly transaction cookie. Taicket exchanges the Discord code at Discord API v10, queries /users/@me and /users/@me/guilds, filters manageable servers, and encrypts the upstream Discord access and refresh tokens with AES-256-GCM before updating McpOAuthTransaction.
- 4
User completes server-scoped consent screen
Taicket renders /oauth/consent with a per-transaction CSRF token, X-Frame-Options: DENY, a server picker (specific manageable servers or All manageable servers), and individual scope toggles (mcp:read, mcp:write, mcp:deploy, mcp:destructive).
- 5
Taicket mints single-use 60-second authorization code
On POST /oauth/consent approval, Taicket verifies the CSRF token and transaction cookie, deletes the pending transaction, creates an McpOAuthGrant, persists SHA-256(code) in McpOAuthCode with a 60-second TTL, and redirects the browser to redirect_uri?code=<auth_code>&state=<state>.
- 6
Client exchanges authorization code at POST /oauth/token
The MCP client submits grant_type=authorization_code with the code, redirect_uri, client_id, code_verifier, and resource=https://mcp.taicket.xyz/mcp. Taicket atomically consumes the code, verifies PKCE S256 in constant time, and returns the 1-hour access token and 30-day rotating refresh token.