Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }

Implementations§

Source§

impl Client

Source

pub fn new(issuer_url: impl Into<String>) -> Self

Source

pub fn with_client_id(self, id: impl Into<String>) -> Self

Source

pub fn with_client_secret(self, s: impl Into<String>) -> Self

Source

pub fn with_auth_method(self, method: ClientAuthMethod) -> Self

Source

pub fn with_redirect_uri(self, uri: impl Into<String>) -> Self

Source

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.

Source

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.

Source

pub async fn discover(&self) -> Result<OidcMetadata, AuthError>

Source

pub async fn jwks(&self) -> Result<Value, AuthError>

Source

pub fn authorization_url( &self, code_challenge: &str, opts: AuthorizationUrlOpts, ) -> Result<String, AuthError>

Source

pub async fn exchange_code( &self, code: &str, code_verifier: &str, opts: TokenOpts, ) -> Result<TokenResponse, AuthError>

Source

pub async fn refresh( &self, refresh_token: &str, opts: TokenOpts, ) -> Result<TokenResponse, AuthError>

Source

pub async fn client_credentials( &self, resource: Vec<String>, scope: Option<String>, opts: TokenOpts, ) -> Result<TokenResponse, AuthError>

Source

pub async fn start_device_authorization( &self, opts: DeviceAuthorizationOpts, ) -> Result<DeviceAuthorization, 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).

Source

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.

Source

pub async fn device_login<F>( &self, on_user_code: F, opts: DeviceAuthorizationOpts, poll: &DevicePollOptions, ) -> Result<TokenResponse, AuthError>

start_device_authorization, hand the codes to on_user_code, then poll_device_token with the same authorization.

Source

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.

Source

pub async fn push_authorization_request( &self, code_challenge: &str, opts: PushedAuthorizationOpts, ) -> Result<PushedAuthorization, AuthError>

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.

Source

pub fn create_authorization_url_from_request_uri( &self, request_uri: &str, ) -> Result<String, AuthError>

The authorize URL for a pushed request: client_id and request_uri only.

Source

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.

Source

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.

Source

pub async fn introspect( &self, token: &str, audience: &str, client_id: Option<&str>, client_secret: Option<&str>, ) -> Result<IntrospectionResponse, AuthError>

Source

pub async fn revoke(&self, token: &str) -> Result<(), AuthError>

Source

pub async fn userinfo( &self, access_token: &str, ) -> Result<UserInfoResponse, AuthError>

The userinfo endpoint with a bearer token.

Source

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.

Source

pub async fn register(&self, input: Value) -> Result<Value, AuthError>

Trait Implementations§

Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnsafeUnpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,