pub struct OAuthHelper { /* private fields */ }Expand description
OAuth helper for CLI authentication flows.
Supports both Authorization Code Flow with PKCE and Device Code Flow, with automatic discovery of OAuth endpoints from the MCP server URL.
Implementations§
Source§impl OAuthHelper
impl OAuthHelper
Sourcepub fn new(config: OAuthConfig) -> Result<OAuthHelper, Error>
pub fn new(config: OAuthConfig) -> Result<OAuthHelper, Error>
Create a new OAuth helper with the given configuration.
Sourcepub async fn get_access_token(&self) -> Result<String, Error>
pub async fn get_access_token(&self) -> Result<String, Error>
Get or refresh access token, performing OAuth flow if needed.
For callers that only need a bearer-header value. Cache consumers that
need to persist refresh_token / expires_at / issuer across runs
should use authorize_with_details instead.
Like get_access_token but returns the full authorization result for
cache persistence.
Cache callers (e.g., cargo pmcp auth login) should prefer this method;
simple callers that just need a bearer header can keep using
get_access_token.
Drives DCR lazily when eligible; runs PKCE via the authorization_code
flow; captures refresh_token, expires_at, scopes, and the
effective issuer + client_id.
§Device-code fallback
If the authorization-code flow fails and the server advertises a
device_authorization_endpoint, this method falls back to device code
flow (RFC 8628). In that case, refresh_token may be None since
RFC 8628 §3.5 does not require it, and scopes falls back to the
requested scopes when the token response does not echo them.
Sourcepub async fn create_middleware_chain(
&self,
) -> Result<Arc<HttpMiddlewareChain>, Error>
pub async fn create_middleware_chain( &self, ) -> Result<Arc<HttpMiddlewareChain>, Error>
Create HTTP middleware chain with OAuth bearer token.
Obtains an access token (from cache, refresh, or interactive flow) and wraps it in a middleware chain suitable for HTTP transports.