MCP browser authentication flow¶
This document describes the current browser-based OAuth authentication flow for the Shopsys MCP server.
The flow has been tested with Claude Code, but it is intended to work with any AI client that supports OAuth-based login for remote MCP servers.
It is not a generic OAuth guide. It follows the current Shopsys MCP integration points and route contracts.
High-level overview¶
When an AI client starts authentication for the configured MCP server, the flow is:
- the client discovers the OAuth metadata
- the client dynamically registers itself
- it opens the Shopsys browser authorization page
- the administrator allows or denies access
- the client exchanges the authorization code for an MCP bearer token
- the client uses that bearer token for MCP requests
Step-by-step¶
1. Authorization server metadata¶
- Route name:
mcp_oauth_metadata - Request:
GET - Response:
issuer,authorization_endpoint,token_endpoint,registration_endpoint, and the supported response type, grant type, auth method, and PKCE method - Note: thanks to this endpoint, the AI client can discover the remaining OAuth endpoints from metadata instead of hardcoding them in advance.
2. Dynamic client registration¶
- Route name:
mcp_oauth_register - Request:
POSTJSON payload withredirect_urisand optionalclient_name - Response: generated
client_id, storedclient_name, and acceptedredirect_uris - Note: the registration is temporary and supports the later authorization and token exchange.
- Rate limit: the endpoint is rate-limited by client IP.
3. Browser authorization request¶
- Route name:
admin_superadmin_mcp_oauth_authorize - Request:
GETquery withresponse_type=code,client_id,redirect_uri,state,code_challenge, andcode_challenge_method=S256 - Behavior: Shopsys validates the request shape and the registered
client_id/redirect_uri, then shows the consent page to the administrator.
4. Consent result¶
- Route name:
admin_superadmin_mcp_oauth_authorize - Request:
POSTsubmit of either allow or deny - Deny redirect:
error=access_deniedandstate - Allow redirect:
codeandstate - Note: the issued authorization code is short-lived and one-time use.
5. Token exchange¶
- Route name:
mcp_oauth_token - Request:
POSTform payload withgrant_type=authorization_code,client_id,redirect_uri,code, andcode_verifier - Validation: registered client exists,
redirect_urimatches the client registration, authorization code exists and is not expired, authorization code matchesclient_id, authorization code matchesredirect_uri, and the PKCE verifier matches the stored challenge - Response:
access_token,token_type=Bearer, andexpires_in - Note: the connected-client token is stored for the concrete OAuth
client_idwith token typeoauthand a readable label derived fromclient_name. - Rate limit: the endpoint is rate-limited by client IP.
6. Authenticated MCP requests¶
- Route name:
_mcp_endpoint - Request: HTTP MCP request with
Authorization: Bearer <access_token> - Behavior: the token is resolved to an administrator, token usage is recorded, and MCP tool access is granted for the authenticated administrator.
- Rate limit: runtime MCP requests always consume an IP-based limit and also consume a token-public-ID limit when the bearer token has the generated token shape.
State used during the flow¶
Temporary state:
- client registrations are stored in cache
- authorization codes are stored in cache
Persistent state:
- connected-client MCP access tokens are stored in the database
Practical note about repeated authorization¶
In practice, an AI client may reuse or recreate its OAuth client registration depending on how it scopes the MCP server configuration.
For example:
- one project may reuse the same OAuth
client_id - another project may register a different OAuth
client_id
That is why the administration can show multiple connected-client tokens with the same human-readable client_name but different technical client_id values.
Manual tokens are separate from this OAuth flow. They can be generated multiple times, have their own labels and expirations, and appear in the same administration overview as OAuth-issued tokens.