pub struct OAuthServer { /* private fields */ }Expand description
OAuth 2.0/2.1 authorization server.
This server implements the OAuth 2.0 authorization code flow with PKCE, which is required for OAuth 2.1 compliance.
Implementations§
Source§impl OAuthServer
impl OAuthServer
Sourcepub fn new(config: OAuthServerConfig) -> Self
pub fn new(config: OAuthServerConfig) -> Self
Creates a new OAuth server with the given configuration.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Creates a new OAuth server with default configuration.
Sourcepub fn config(&self) -> &OAuthServerConfig
pub fn config(&self) -> &OAuthServerConfig
Returns the server configuration.
Sourcepub fn register_client(&self, client: OAuthClient) -> Result<(), OAuthError>
pub fn register_client(&self, client: OAuthClient) -> Result<(), OAuthError>
Registers a new OAuth client.
§Errors
Returns an error if:
- A client with the same ID already exists
- Public clients are not allowed and the client has no secret
Sourcepub fn unregister_client(&self, client_id: &str) -> Result<(), OAuthError>
pub fn unregister_client(&self, client_id: &str) -> Result<(), OAuthError>
Unregisters an OAuth client.
This also revokes all tokens issued to the client.
Sourcepub fn get_client(&self, client_id: &str) -> Option<OAuthClient>
pub fn get_client(&self, client_id: &str) -> Option<OAuthClient>
Gets a registered client by ID.
Sourcepub fn list_clients(&self) -> Vec<OAuthClient>
pub fn list_clients(&self) -> Vec<OAuthClient>
Lists all registered clients.
Validates an authorization request and creates an authorization code.
This is called after the resource owner has authenticated and approved the authorization request.
§Arguments
request- The authorization request parameterssubject- The authenticated user’s identifier (optional)
§Returns
Returns the authorization code and redirect URI on success.
Sourcepub fn token(&self, request: &TokenRequest) -> Result<TokenResponse, OAuthError>
pub fn token(&self, request: &TokenRequest) -> Result<TokenResponse, OAuthError>
Exchanges an authorization code or refresh token for tokens.
Sourcepub fn revoke(
&self,
token: &str,
client_id: &str,
client_secret: Option<&str>,
) -> Result<(), OAuthError>
pub fn revoke( &self, token: &str, client_id: &str, client_secret: Option<&str>, ) -> Result<(), OAuthError>
Revokes a token (access or refresh).
Per RFC 7009, this always returns success even if the token was not found.
Sourcepub fn validate_access_token(&self, token: &str) -> Option<OAuthToken>
pub fn validate_access_token(&self, token: &str) -> Option<OAuthToken>
Validates an access token and returns its metadata.
This is used internally and by the OAuthTokenVerifier.
Sourcepub fn token_verifier(self: &Arc<Self>) -> OAuthTokenVerifier
pub fn token_verifier(self: &Arc<Self>) -> OAuthTokenVerifier
Creates a token verifier for use with MCP [TokenAuthProvider].
Sourcepub fn cleanup_expired(&self)
pub fn cleanup_expired(&self)
Removes expired tokens and authorization codes.
Call this periodically to prevent memory growth.
Sourcepub fn stats(&self) -> OAuthServerStats
pub fn stats(&self) -> OAuthServerStats
Returns statistics about the server state.