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 crate::auth::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.
Auto Trait Implementations§
impl !Freeze for OAuthServer
impl RefUnwindSafe for OAuthServer
impl Send for OAuthServer
impl Sync for OAuthServer
impl Unpin for OAuthServer
impl UnsafeUnpin for OAuthServer
impl UnwindSafe for OAuthServer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more