pub struct Client { /* private fields */ }Implementations§
Source§impl Client
impl Client
pub fn new(issuer_url: impl Into<String>) -> Self
pub fn with_client_id(self, id: impl Into<String>) -> Self
pub fn with_client_secret(self, s: impl Into<String>) -> Self
pub fn with_auth_method(self, method: ClientAuthMethod) -> Self
pub fn with_redirect_uri(self, uri: impl Into<String>) -> Self
Sourcepub fn with_client_assertion_key(self, key: ClientAssertionKey) -> Self
pub fn with_client_assertion_key(self, key: ClientAssertionKey) -> Self
Authenticate with private_key_jwt: every token and pushed authorization request carries a new signed
assertion. Implies ClientAuthMethod::PrivateKeyJwt; a client secret or another method is refused when a
request is made.
Sourcepub fn with_dpop(self, key: DpopKey) -> Self
pub fn with_dpop(self, key: DpopKey) -> Self
Sender-constrain tokens with DPoP: exchange_code and refresh send a proof, and
userinfo_for and dpop_headers use it for a bound token.
pub async fn discover(&self) -> Result<OidcMetadata, AuthError>
pub async fn jwks(&self) -> Result<Value, AuthError>
pub async fn exchange_code( &self, code: &str, code_verifier: &str, opts: TokenOpts, ) -> Result<TokenResponse, AuthError>
pub async fn refresh( &self, refresh_token: &str, opts: TokenOpts, ) -> Result<TokenResponse, AuthError>
pub async fn client_credentials( &self, resource: Vec<String>, scope: Option<String>, opts: TokenOpts, ) -> Result<TokenResponse, AuthError>
Ask for a device code and a user code.
Show user_code and verification_uri (or verification_uri_complete, for a QR code) to the person, then call
poll_device_token. The client must be registered for the device_code grant; a
confidential client authenticates with its secret (private_key_jwt is not accepted at this endpoint by the
service).
Sourcepub async fn poll_device_token(
&self,
device: &DeviceAuthorization,
opts: TokenOpts,
poll: &DevicePollOptions,
) -> Result<TokenResponse, AuthError>
pub async fn poll_device_token( &self, device: &DeviceAuthorization, opts: TokenOpts, poll: &DevicePollOptions, ) -> Result<TokenResponse, AuthError>
Poll the token endpoint until the person approves.
Waits the interval before each poll, adds five seconds after slow_down, and stops with the service’s OAuth
error for access_denied, expired_token or anything else (and with expired_token once the device code’s own
lifetime would pass). Cancel through the CancelToken in poll to stop
(AuthError::Cancelled). A network failure is returned, not retried; call again with the same authorization
to resume.
Sourcepub async fn device_login<F>(
&self,
on_user_code: F,
opts: DeviceAuthorizationOpts,
poll: &DevicePollOptions,
) -> Result<TokenResponse, AuthError>where
F: FnOnce(&DeviceAuthorization),
pub async fn device_login<F>(
&self,
on_user_code: F,
opts: DeviceAuthorizationOpts,
poll: &DevicePollOptions,
) -> Result<TokenResponse, AuthError>where
F: FnOnce(&DeviceAuthorization),
start_device_authorization, hand the codes to on_user_code, then
poll_device_token with the same authorization.
Sourcepub async fn exchange_token(
&self,
subject_token: &str,
opts: TokenExchangeOpts,
) -> Result<TokenResponse, AuthError>
pub async fn exchange_token( &self, subject_token: &str, opts: TokenExchangeOpts, ) -> Result<TokenResponse, AuthError>
Exchange an access token for a delegated one (the service’s delegation grants decide whether it may).
subject_token is the delegator’s access token; opts.actor_token the acting party’s. The token types default to
the only one the service supports. Never carries a DPoP proof: the service accepts one for the code and refresh
grants only.
Send the authorize parameters to the service directly and get a one-use request_uri back, so the browser
carries nothing the person could read or edit.
Authenticates like the token endpoint. Then redirect to
create_authorization_url_from_request_uri.
The authorize URL for a pushed request: client_id and request_uri only.
Sourcepub fn create_end_session_url(
&self,
params: &EndSessionParams,
) -> Result<String, AuthError>
pub fn create_end_session_url( &self, params: &EndSessionParams, ) -> Result<String, AuthError>
The URL to send the person’s browser to in order to end their session.
Uses the discovered end_session_endpoint when it is on the issuer’s origin, <issuer>/oauth/end_session
otherwise. The service redirects to post_logout_redirect_uri only for an id_token_hint that names a client
for which that URI is registered. params.end_session_endpoint is ignored here: the client supplies it.
Sourcepub fn dpop_headers(
&self,
access_token: &str,
method: &str,
url: &str,
) -> Result<Vec<(String, String)>, AuthError>
pub fn dpop_headers( &self, access_token: &str, method: &str, url: &str, ) -> Result<Vec<(String, String)>, AuthError>
The Authorization: DPoP <token> and DPoP: <proof> headers for a request to any resource server, with the
proof bound to the token (ath), the method and the URL (query and fragment excluded). Needs the key from
with_dpop. Call once per request: a proof is single use.
pub async fn introspect( &self, token: &str, audience: &str, client_id: Option<&str>, client_secret: Option<&str>, ) -> Result<IntrospectionResponse, AuthError>
pub async fn revoke(&self, token: &str) -> Result<(), AuthError>
Sourcepub async fn userinfo(
&self,
access_token: &str,
) -> Result<UserInfoResponse, AuthError>
pub async fn userinfo( &self, access_token: &str, ) -> Result<UserInfoResponse, AuthError>
The userinfo endpoint with a bearer token.
Sourcepub async fn userinfo_for(
&self,
access_token: &str,
token_type: TokenType,
) -> Result<UserInfoResponse, AuthError>
pub async fn userinfo_for( &self, access_token: &str, token_type: TokenType, ) -> Result<UserInfoResponse, AuthError>
The userinfo endpoint. TokenType::Dpop is for a token issued with a DPoP proof: it is sent under the DPoP
scheme with a proof bound to it, and needs the key from with_dpop.