OAuthProvider
FastMCP provides theOAuthProvider abstract class that implements the OAuth 2.1 specification. To use this pattern, you must subclass OAuthProvider and implement all required abstract methods.
OAuthProvider handles OAuth endpoints, protocol flows, and security requirements, but delegates all storage, user management, and business logic to your implementation of the abstract methods.Required Implementation
You must implement these abstract methods to create a functioning OAuth server:Client Management
Authorization Flow
Token Management
Token Management Methods
async method
Exchange authorization code for access and refresh tokens. Must validate code and create new tokens.
async method
Load refresh token from storage by token string. Return
None if token is invalid or expired.async method
Exchange refresh token for new access/refresh token pair. Must validate scopes and token.
async method
Load an access token by its token string.
async method
Revoke access or refresh token, marking it as invalid in storage.
async method
Verify bearer token for incoming requests. Return
AccessToken if valid, None if invalid.
