Struct rocket_oauth2::TokenResponse
source · pub struct TokenResponse<K> { /* private fields */ }
Expand description
The server’s response to a successful token exchange, defined in in RFC 6749 §5.1.
TokenResponse<K>
implements FromRequest
, and is used in the callback
route to complete the token exchange.
Example
use rocket_oauth2::TokenResponse;
#[get("/auth")]
fn auth_callback(token: TokenResponse<Auth>, cookies: &CookieJar<'_>) -> Redirect {
// ...
}
Implementations§
source§impl<K> TokenResponse<K>
impl<K> TokenResponse<K>
sourcepub fn cast<L>(self) -> TokenResponse<L>
pub fn cast<L>(self) -> TokenResponse<L>
Reinterpret this TokenResponse
as if it were keyed by L
instead.
This function can be used to treat disparate TokenResponse
s as a
single concrete type such as TokenResponse<()>
to avoid an explosion
of generic bounds.
Example
use rocket_oauth2::TokenResponse;
struct GitHub;
fn use_nongeneric_token(token: TokenResponse<()>) {
// ...
}
#[rocket::get("/login/github")]
fn login_github(token: TokenResponse<GitHub>) {
use_nongeneric_token(token.cast());
}
sourcepub fn as_value(&self) -> &Value
pub fn as_value(&self) -> &Value
Get the TokenResponse data as a raw JSON Value. It is guaranteed to be of type Object.
Example
use rocket_oauth2::TokenResponse;
struct MyProvider;
#[rocket::get("/login/github")]
fn login_github(token: TokenResponse<MyProvider>) {
let custom_data = token.as_value().get("custom_data").unwrap().as_str();
}
sourcepub fn access_token(&self) -> &str
pub fn access_token(&self) -> &str
Get the access token issued by the authorization server.
Example
use rocket_oauth2::TokenResponse;
struct GitHub;
#[rocket::get("/login/github")]
fn login_github(token: TokenResponse<GitHub>) {
let access_token = token.access_token();
}
sourcepub fn token_type(&self) -> &str
pub fn token_type(&self) -> &str
Get the type of token, described in RFC 6749 §7.1.
Example
use rocket_oauth2::TokenResponse;
struct GitHub;
#[rocket::get("/login/github")]
fn login_github(token: TokenResponse<GitHub>) {
let token_type = token.token_type();
}
sourcepub fn expires_in(&self) -> Option<i64>
pub fn expires_in(&self) -> Option<i64>
Get the lifetime in seconds of the access token, if the authorization server provided one.
Example
use rocket_oauth2::TokenResponse;
struct GitHub;
#[rocket::get("/login/github")]
fn login_github(token: TokenResponse<GitHub>) {
if let Some(expires_in) = token.expires_in() {
println!("Token expires in {} seconds", expires_in);
}
}
sourcepub fn refresh_token(&self) -> Option<&str>
pub fn refresh_token(&self) -> Option<&str>
Get the refresh token, if the server provided one.
Example
use rocket_oauth2::TokenResponse;
struct GitHub;
#[rocket::get("/login/github")]
fn login_github(token: TokenResponse<GitHub>) {
if let Some(refresh_token) = token.refresh_token() {
println!("Got a refresh token! '{}'", refresh_token);
}
}
sourcepub fn scope(&self) -> Option<&str>
pub fn scope(&self) -> Option<&str>
Get the (space-separated) list of scopes associated with the access token. The authorization server is required to provide this if it differs from the requested set of scopes.
If scope
was not provided by the server as a string, this method will
return None
. For those providers, use `.as_value().get(“scope”)
instead.
Example
use rocket_oauth2::TokenResponse;
struct GitHub;
#[rocket::get("/login/github")]
fn login_github(token: TokenResponse<GitHub>) {
if let Some(scope) = token.scope() {
println!("Token scope: '{}'", scope);
}
}
Trait Implementations§
source§impl<K: Clone> Clone for TokenResponse<K>
impl<K: Clone> Clone for TokenResponse<K>
source§fn clone(&self) -> TokenResponse<K>
fn clone(&self) -> TokenResponse<K>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<K: Debug> Debug for TokenResponse<K>
impl<K: Debug> Debug for TokenResponse<K>
source§impl<'r, K: 'static> FromRequest<'r> for TokenResponse<K>
impl<'r, K: 'static> FromRequest<'r> for TokenResponse<K>
source§fn from_request<'life0, 'async_trait>(
request: &'r Request<'life0>
) -> Pin<Box<dyn Future<Output = Outcome<Self, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'r: 'async_trait,
'life0: 'async_trait,
fn from_request<'life0, 'async_trait>(
request: &'r Request<'life0>
) -> Pin<Box<dyn Future<Output = Outcome<Self, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'r: 'async_trait,
'life0: 'async_trait,
Handle the redirect callback, delegating to the Adapter to perform the token exchange.
source§impl<K: PartialEq> PartialEq for TokenResponse<K>
impl<K: PartialEq> PartialEq for TokenResponse<K>
source§fn eq(&self, other: &TokenResponse<K>) -> bool
fn eq(&self, other: &TokenResponse<K>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<K: 'static> Sentinel for TokenResponse<K>
impl<K: 'static> Sentinel for TokenResponse<K>
impl<K> StructuralPartialEq for TokenResponse<K>
Auto Trait Implementations§
impl<K> RefUnwindSafe for TokenResponse<K>
impl<K> Send for TokenResponse<K>
impl<K> Sync for TokenResponse<K>
impl<K> Unpin for TokenResponse<K>
impl<K> UnwindSafe for TokenResponse<K>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoCollection<T> for T
impl<T> IntoCollection<T> for T
§fn into_collection<A>(self) -> SmallVec<A>where
A: Array<Item = T>,
fn into_collection<A>(self) -> SmallVec<A>where
A: Array<Item = T>,
self
into a collection.fn mapped<U, F, A>(self, f: F) -> SmallVec<A>where
F: FnMut(T) -> U,
A: Array<Item = U>,
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute
] value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
[Quirk
] value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition
] value
applies. Replaces any previous condition.
See the crate level docs for more details.
Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);