Skip to main content

IssuedToken

Struct IssuedToken 

Source
pub struct IssuedToken { /* private fields */ }
Expand description

A successfully redeemed grant.

Obtained only from IssuedToken::parse, so an IssuedToken that exists is one that parsed. token_type is not carried because the only value that can produce this type is Bearer — the check happened at the door.

Implementations§

Source§

impl IssuedToken

Source

pub const fn access_token(&self) -> &AccessToken

The token to present as a bearer credential.

Source

pub const fn refresh_token(&self) -> Option<&RefreshToken>

The refresh token, if the server issued one.

Source

pub fn scope(&self) -> Option<&str>

The scope actually granted.

RFC 6749 §5.1 makes this OPTIONAL, and an absent value does not mean “everything that was asked for” — §5.1 says the server treated it as equal to the requested scope, and §3.3 lets it narrow that silently. A client that reads None as “unlimited” would present a token for a grant it never received.

Source

pub const fn extra(&self) -> &Map<String, Value>

Members of the response this build does not model.

Source

pub fn parse(body: &[u8]) -> Result<Self, TokenResponseError>

Parse an RFC 6749 §5.1 success body, or an RFC 6749 §5.2 error body.

§Errors

TokenResponseError::AuthorizationServer when the body names an error, carrying the server’s own error code rather than a guess. TokenResponseError::Malformed when the body is not JSON, or omits the two REQUIRED members. TokenResponseError::UnsupportedTokenType when token_type is something other than Bearer under a case-insensitive comparison.

§Examples
let body = br#"{"access_token":"at-1","token_type":"Bearer","expires_in":3600}"#;
let issued = IssuedToken::parse(body)?;

assert_eq!(issued.access_token().as_str(), "at-1");
assert!(issued.refresh_token().is_none());

let refused = br#"{"error":"invalid_grant","error_description":"expired"}"#;
assert!(matches!(
    IssuedToken::parse(refused),
    Err(TokenResponseError::AuthorizationServer { error, .. })
        if error == "invalid_grant"
));

Trait Implementations§

Source§

impl Debug for IssuedToken

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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