Principle:1mcp app Agent OAuth Authentication
| Knowledge Sources | |
|---|---|
| Domains | Security, Authentication |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Pattern that secures the 1MCP runtime with OAuth 2.1 authentication, authorization code grant flow, refresh token rotation with duplicate detection, and tag-based scope validation for template context authorization.
Description
OAuth Authentication protects the 1MCP runtime by requiring clients to authenticate via OAuth 2.1 before accessing MCP tools. The runtime acts as both an OAuth resource server (for inbound client authentication) and an OAuth client (for upstream server authentication). The authorization code grant flow is initiated through a browser-accessible dashboard at the `/oauth` endpoint. Refresh tokens use rotating families with duplicate detection: each refresh produces a new token and invalidates the old one, and reuse of a consumed token triggers detection and invalidation of the entire family. Tag-based scope validation adds an authorization layer for template context access.
Usage
Use this principle when:
- The runtime must authenticate inbound clients before serving MCP requests
- Upstream MCP servers require OAuth authentication for connection
- Refresh tokens must be rotated on each use with duplicate detection for security
- Template context access must be authorized based on tag-based scopes
- An OAuth dashboard is needed for browser-based authorization code grant initiation
Theoretical Basis
The authorization code grant flow:
Failed to parse (syntax error): {\displaystyle \xrightarrow{\text{auth\_code}} \text{Token Endpoint} \xrightarrow{\text{access\_token + refresh\_token}} \text{Client} }
Refresh token rotation with families:
refresh(old_token) → { access_token_new, refresh_token_new }
invalidate(old_token)
family_id = constant across rotations
if old_token reused → invalidate entire family (duplicate detection)
Tag-based scope validation:
Practical Guide
- Enable auth via `--enable-auth` CLI flag and set `--external-url` for OAuth redirects
- Serve an OAuth dashboard at `/oauth` for browser-based authorization code grant
- Use rotating token families for refresh tokens with duplicate detection per ADR-0014/0015
- Heal credential files on read to recover from partial writes per ADR-0016
- Enable tag-based scope validation via `--enable-scope-validation` for template context authorization
- Verify authentication status with `auth status` and export credentials with `auth export`