Authentication

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.
Dynamic Client Registration requesthttp
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"
}
Dynamic Client Registration response (201 Created)json
{
  "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. 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 requesthttp
    GET /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. 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. 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. 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. 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. 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.

Authorization Request Parameters

ParameterRequiredValidation Rule
response_typeYesMust be exactly code
client_idYesRegistered DCR client_id or valid HTTPS CIMD URL
redirect_uriYesExact byte-for-byte match against registered redirect_uris
code_challengeYesBase64url-encoded 32-byte SHA-256 digest (43 characters)
code_challenge_methodYesMust be exactly S256 (plain is rejected)
resourceYesMust normalize to https://mcp.taicket.xyz/mcp (RFC 8707)
scopeOptionalSpace-delimited subset of mcp:read, mcp:write, mcp:deploy, mcp:destructive
stateRecommendedOpaque client CSRF token returned verbatim on redirect

Strict redirect URI matching

Taicket never performs prefix, wildcard, or query-parameter-tolerant matching on redirect_uri. If client_id or redirect_uri fails validation, Taicket renders a direct error page and never redirects the browser to an unverified target.

Related documentation