twitch_oauth2

Trait TwitchToken

Source
pub trait TwitchToken {
    // Required methods
    fn token_type() -> BearerTokenType;
    fn client_id(&self) -> &ClientId;
    fn token(&self) -> &AccessToken;
    fn login(&self) -> Option<&UserNameRef>;
    fn user_id(&self) -> Option<&UserIdRef>;
    fn refresh_token<'a, 'life0, 'async_trait, C>(
        &'life0 mut self,
        http_client: &'a C,
    ) -> Pin<Box<dyn Future<Output = Result<(), RefreshTokenError<<C as Client>::Error>>> + Send + 'async_trait>>
       where Self: Sized + 'async_trait,
             C: Client + 'async_trait,
             'a: 'async_trait,
             'life0: 'async_trait;
    fn expires_in(&self) -> Duration;
    fn scopes(&self) -> &[Scope];

    // Provided methods
    fn is_elapsed(&self) -> bool { ... }
    fn validate_token<'a, 'life0, 'async_trait, C>(
        &'life0 self,
        http_client: &'a C,
    ) -> Pin<Box<dyn Future<Output = Result<ValidatedToken, ValidationError<<C as Client>::Error>>> + Send + 'async_trait>>
       where Self: Sized + Sync + 'async_trait,
             C: Client + 'async_trait,
             'a: 'async_trait,
             'life0: 'async_trait { ... }
    fn revoke_token<'a, 'async_trait, C>(
        self,
        http_client: &'a C,
    ) -> Pin<Box<dyn Future<Output = Result<(), RevokeTokenError<<C as Client>::Error>>> + Send + 'async_trait>>
       where Self: Sized + Send + 'async_trait,
             C: Client + 'async_trait,
             'a: 'async_trait { ... }
}
Expand description

Trait for twitch tokens to get fields and generalize over AppAccessToken and UserToken

Required Methods§

Source

fn token_type() -> BearerTokenType

Get the type of token.

Source

fn client_id(&self) -> &ClientId

Client ID associated with the token. Twitch requires this in all helix API calls

Source

fn token(&self) -> &AccessToken

Get the AccessToken for authenticating

§Example
use twitch_oauth2::TwitchToken;
println!("token: {}", user_token.token().secret());
Source

fn login(&self) -> Option<&UserNameRef>

Get the username associated to this token

Source

fn user_id(&self) -> Option<&UserIdRef>

Get the user id associated to this token

Source

fn refresh_token<'a, 'life0, 'async_trait, C>( &'life0 mut self, http_client: &'a C, ) -> Pin<Box<dyn Future<Output = Result<(), RefreshTokenError<<C as Client>::Error>>> + Send + 'async_trait>>
where Self: Sized + 'async_trait, C: Client + 'async_trait, 'a: 'async_trait, 'life0: 'async_trait,

Available on crate feature client only.

Refresh this token, changing the token to a newer one

Source

fn expires_in(&self) -> Duration

Get current lifetime of token.

Source

fn scopes(&self) -> &[Scope]

Retrieve scopes attached to the token

Provided Methods§

Source

fn is_elapsed(&self) -> bool

Returns whether or not the token is expired.

use twitch_oauth2::{UserToken, TwitchToken};
if user_token.is_elapsed() {
    user_token.refresh_token(&reqwest::Client::builder().redirect(reqwest::redirect::Policy::none()).build()?).await?;
}
Source

fn validate_token<'a, 'life0, 'async_trait, C>( &'life0 self, http_client: &'a C, ) -> Pin<Box<dyn Future<Output = Result<ValidatedToken, ValidationError<<C as Client>::Error>>> + Send + 'async_trait>>
where Self: Sized + Sync + 'async_trait, C: Client + 'async_trait, 'a: 'async_trait, 'life0: 'async_trait,

Available on crate feature client only.

Validate this token. Should be checked on regularly, according to https://dev.twitch.tv/docs/authentication/validate-tokens/

§Note

This will not mutate any current data in the TwitchToken

Source

fn revoke_token<'a, 'async_trait, C>( self, http_client: &'a C, ) -> Pin<Box<dyn Future<Output = Result<(), RevokeTokenError<<C as Client>::Error>>> + Send + 'async_trait>>
where Self: Sized + Send + 'async_trait, C: Client + 'async_trait, 'a: 'async_trait,

Available on crate feature client only.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T: TwitchToken + Send> TwitchToken for Box<T>

Source§

fn token_type() -> BearerTokenType

Source§

fn client_id(&self) -> &ClientId

Source§

fn token(&self) -> &AccessToken

Source§

fn login(&self) -> Option<&UserNameRef>

Source§

fn user_id(&self) -> Option<&UserIdRef>

Source§

fn refresh_token<'a, 'life0, 'async_trait, C>( &'life0 mut self, http_client: &'a C, ) -> Pin<Box<dyn Future<Output = Result<(), RefreshTokenError<<C as Client>::Error>>> + Send + 'async_trait>>
where Self: Sized + 'async_trait, C: Client + 'async_trait, 'a: 'async_trait, 'life0: 'async_trait,

Available on crate feature client only.
Source§

fn expires_in(&self) -> Duration

Source§

fn scopes(&self) -> &[Scope]

Implementors§