Implement OAuth2 Specs #88
Replies: 3 comments 1 reply
-
|
Existing OAuth implementations require gated approval to trusted OAuth clients. DO NOT GIVE OAuth keys without centralized/federated authorization from a signing-source within Nexlayer. Third-part OAuth apps MUST be associated with a verified users. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
For MCP clients, I would avoid carrying browser session-token semantics forward and make the OAuth boundary explicit. A practical model is:
The most important distinction is that an MCP token should authorize a bounded tool action, not impersonate the whole web session. That makes third-party clients easier to reason about and safer to revoke. |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
Generalizing Session Tokens to Follow OAuth 2.0 Specifications
Overview
This guide explains how to align session token implementations with OAuth 2.0 standards (RFC 6749) to create interoperable, secure authentication for native MCP clients and third-party integrations.
The Problem: Non-Standard Session Tokens
Current Implementation (Nexlayer):
next-auth.session-tokencookie interception viaWKWebViewsessionToken/sessionId/userIPparameters injected into MCP tool callsOAuth 2.0 Standard:
OAuth 2.0 Architecture for Session Tokens
Core Components
1. Authorization Server Role
The authorization server issues access tokens to the client after successfully authenticating the resource owner and obtaining authorization.
For session-like scenarios, this means:
2. Access Token vs. Session Token
Recommendation: Replace
sessionTokenwith OAuth 2.0 access tokens that encode session context.Proposed Token Structure
Option A: Opaque Access Token with Server-Side Lookup
Pros:
Cons:
Option B: JWT-Based Access Token
Pros:
Cons:
Recommendation for MCP: JWT access tokens with short expiration (15–60 min) + optional refresh tokens for long-lived sessions.
Implementation: Authorization Code + PKCE Flow
1. Register Native App Client
Request to Nexlayer OAuth Server:
{ "client_name": "mac-native-mcp", "client_type": "public", "redirect_uris": ["nexlayer-mac-native://oauth/callback"], "response_types": ["code"], "grant_types": ["authorization_code", "refresh_token"], "token_endpoint_auth_method": "none" }Response:
{ "client_id": "mac-native-mcp-xyz", "client_secret": null, "redirect_uris": ["nexlayer-mac-native://oauth/callback"], "token_endpoint_auth_method": "none" }2. Authorization Request with PKCE
PKCE works by the app first generating a new secret each time it starts the Authorization Code flow, and it sends a hash of the secret in the initial authorization request.
Step 1: Generate PKCE Challenge
Step 2: Redirect to Authorization Endpoint
Step 3: User Authenticates
ASWebAuthenticationSession)Step 4: Authorization Redirect
3. Token Exchange
Step 5: Back-Channel Token Request
Step 6: Token Response
{ "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "token_type": "Bearer", "expires_in": 3600, "refresh_token": "refresh-token-xyz", "scope": "read:credits write:coupon read:referral" }Step 7: Store Tokens Securely
4. MCP Tool Calls with Access Token
Instead of:
Use OAuth Bearer Token:
Token Refresh & Lifecycle
Refresh Token Flow
Refresh Token Rotation is strongly recommended by RFC 9700 (Security BCP) and OAuth 2.1, making Refresh Tokens single-use and replacing them on every refresh.
When Access Token Expires:
Response:
{ "access_token": "new-access-token...", "token_type": "Bearer", "expires_in": 3600, "refresh_token": "new-refresh-token-xyz" }Client Behavior:
401 Unauthorized, refresh using refresh tokenSecurity Best Practices
1. Token Expiration Strategy
2. PKCE Mandatory for Native Apps
The latest Security Best Current Practice recommends using PKCE for all types of apps, even apps with a client secret.
3. No Client Secret in Native Apps
4. Secure Token Storage
5. Token Revocation on Logout
POST https://nexlayer.com/oauth/revoke Content-Type: application/x-www-form-urlencoded token=access-token-value& client_id=mac-native-mcp-xyzAPI Compatibility Layer
Backward Compatibility: Adapter Pattern
If Nexlayer's MCP tools still expect
sessionTokenparameter:Better: Update Nexlayer MCP tools to:
Authorizationheadersub(user ID),scope, etc.sessionTokenparameterDiscovery: OAuth Server Metadata
Authorization Server Metadata (RFC 8414) allows clients to discover OAuth endpoints and authorization server capabilities.
Request:
Response (OIDC Discovery):
{ "issuer": "https://nexlayer.com", "authorization_endpoint": "https://nexlayer.com/oauth/authorize", "token_endpoint": "https://nexlayer.com/oauth/token", "revocation_endpoint": "https://nexlayer.com/oauth/revoke", "introspection_endpoint": "https://nexlayer.com/oauth/introspect", "jwks_uri": "https://nexlayer.com/.well-known/jwks.json", "scopes_supported": ["read:credits", "write:coupon", "read:referral"], "response_types_supported": ["code"], "grant_types_supported": ["authorization_code", "refresh_token"], "token_endpoint_auth_methods_supported": ["none"] }Benefit: Clients auto-discover endpoints without hardcoding.
Implementation Checklist
OAuth Authorization Server Setup
/oauth/authorizeendpoint/oauth/tokenendpoint/oauth/revokeendpoint.well-known/openid-configurationNative Client (mac-native-mcp)
ASWebAuthenticationSessionMCP Tool Backend
sessionTokenparam needed)Testing & Security
References
Migration Path
sessionTokenparametersessionToken, require Bearer tokensThis phased approach ensures backward compatibility while modernizing the authentication layer.
Beta Was this translation helpful? Give feedback.
All reactions