Skip to main content

TokenResponse

Struct TokenResponse 

Source
pub struct TokenResponse {
    pub access_token: String,
    pub token_type: String,
    pub expires_in: Option<u64>,
    pub refresh_token: Option<String>,
    pub scope: Option<Scopes>,
    pub id_token: Option<String>,
    pub extra: Json,
}
Expand description

What a token endpoint returns on success.

Debug redacts the secrets. This type is what a developer prints while debugging a grant, and an access token in a log file is a live credential.

Fields§

§access_token: String§token_type: String§expires_in: Option<u64>

Seconds from issue, not an absolute time — that is what the wire carries.

§refresh_token: Option<String>§scope: Option<Scopes>

Present when the provider granted something other than what was asked.

§id_token: Option<String>

OpenID Connect’s identity token, when openid was requested.

§extra: Json

Everything else the provider sent, kept so provider-specific fields are not lost.

Implementations§

Source§

impl TokenResponse

Source

pub fn bearer(access_token: impl Into<String>) -> TokenResponse

Source

pub fn expiring_in(self, seconds: u64) -> TokenResponse

Source

pub fn with_refresh_token(self, token: impl Into<String>) -> TokenResponse

Source

pub fn with_scopes(self, scopes: Scopes) -> TokenResponse

Source

pub fn from_json(body: &Json) -> Result<TokenResponse, OAuthError>

Parse a token endpoint’s JSON response.

An error field wins over everything else, whatever the HTTP status — enough providers return 200 with an error body that trusting the status alone means silently treating a failure as a success.

Source

pub fn to_json(&self) -> Json

Source

pub fn authorization_header(&self) -> String

The value for an Authorization header.

Source

pub fn expires_within(&self, elapsed_seconds: u64, slack: u64) -> bool

Whether the token is within slack seconds of expiring.

Refreshing early is deliberate: a token that expires while a request is in flight fails, and the caller has no way to tell that apart from a revoked token.

Trait Implementations§

Source§

impl Clone for TokenResponse

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TokenResponse

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.