Trait twitch_oauth2::TwitchToken[][src]

pub trait TwitchToken {
    fn token_type() -> BearerTokenType;
fn client_id(&self) -> &ClientId;
fn token(&self) -> &AccessToken;
fn login(&self) -> Option<&str>;
fn user_id(&self) -> Option<&str>;
#[must_use] fn refresh_token<'life0, 'async_trait, RE, C, F>(
        &'life0 mut self,
        http_client: C
    ) -> Pin<Box<dyn Future<Output = Result<(), RefreshTokenError<RE>>> + Send + 'async_trait>>
    where
        Self: Sized,
        RE: Error + Send + Sync + 'static,
        C: FnOnce(HttpRequest) -> F + Send,
        F: Future<Output = Result<HttpResponse, RE>> + Send,
        RE: 'async_trait,
        C: 'async_trait,
        F: 'async_trait,
        'life0: 'async_trait,
        Self: 'async_trait
;
fn expires_in(&self) -> Duration;
fn scopes(&self) -> &[Scope]; fn is_elapsed(&self) -> bool { ... }
#[must_use] fn validate_token<'life0, 'async_trait, RE, C, F>(
        &'life0 self,
        http_client: C
    ) -> Pin<Box<dyn Future<Output = Result<ValidatedToken, ValidationError<RE>>> + Send + 'async_trait>>
    where
        Self: Sized,
        RE: Error + Send + Sync + 'static,
        C: FnOnce(HttpRequest) -> F + Send,
        F: Future<Output = Result<HttpResponse, RE>> + Send,
        RE: 'async_trait,
        C: 'async_trait,
        F: 'async_trait,
        'life0: 'async_trait,
        Self: Sync + 'async_trait
, { ... }
#[must_use] fn revoke_token<'async_trait, RE, C, F>(
        self,
        http_client: C
    ) -> Pin<Box<dyn Future<Output = Result<(), RevokeTokenError<RE>>> + Send + 'async_trait>>
    where
        Self: Sized,
        RE: Error + Send + Sync + 'static,
        C: FnOnce(HttpRequest) -> F + Send,
        F: Future<Output = Result<HttpResponse, RE>> + Send,
        RE: 'async_trait,
        C: 'async_trait,
        F: 'async_trait,
        Self: Send + 'async_trait
, { ... } }

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

Required methods

fn token_type() -> BearerTokenType[src]

Get the type of token.

fn client_id(&self) -> &ClientId[src]

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

fn token(&self) -> &AccessToken[src]

Get the AccessToken for authenticating

Example

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

fn login(&self) -> Option<&str>[src]

Get the username associated to this token

fn user_id(&self) -> Option<&str>[src]

Get the user id associated to this token

#[must_use]
fn refresh_token<'life0, 'async_trait, RE, C, F>(
    &'life0 mut self,
    http_client: C
) -> Pin<Box<dyn Future<Output = Result<(), RefreshTokenError<RE>>> + Send + 'async_trait>> where
    Self: Sized,
    RE: Error + Send + Sync + 'static,
    C: FnOnce(HttpRequest) -> F + Send,
    F: Future<Output = Result<HttpResponse, RE>> + Send,
    RE: 'async_trait,
    C: 'async_trait,
    F: 'async_trait,
    'life0: 'async_trait,
    Self: 'async_trait, 
[src]

Refresh this token, changing the token to a newer one

fn expires_in(&self) -> Duration[src]

Get current lifetime of token.

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

Retrieve scopes attached to the token

Loading content...

Provided methods

fn is_elapsed(&self) -> bool[src]

Returns whether or not the token is expired.

use twitch_oauth2::{UserToken, TwitchToken, client::reqwest_http_client};
if user_token.is_elapsed() {
    user_token.refresh_token(reqwest_http_client).await?;
}

#[must_use]
fn validate_token<'life0, 'async_trait, RE, C, F>(
    &'life0 self,
    http_client: C
) -> Pin<Box<dyn Future<Output = Result<ValidatedToken, ValidationError<RE>>> + Send + 'async_trait>> where
    Self: Sized,
    RE: Error + Send + Sync + 'static,
    C: FnOnce(HttpRequest) -> F + Send,
    F: Future<Output = Result<HttpResponse, RE>> + Send,
    RE: 'async_trait,
    C: 'async_trait,
    F: 'async_trait,
    'life0: 'async_trait,
    Self: Sync + 'async_trait, 
[src]

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

Note

This will not mutate any current data in the TwitchToken

#[must_use]
fn revoke_token<'async_trait, RE, C, F>(
    self,
    http_client: C
) -> Pin<Box<dyn Future<Output = Result<(), RevokeTokenError<RE>>> + Send + 'async_trait>> where
    Self: Sized,
    RE: Error + Send + Sync + 'static,
    C: FnOnce(HttpRequest) -> F + Send,
    F: Future<Output = Result<HttpResponse, RE>> + Send,
    RE: 'async_trait,
    C: 'async_trait,
    F: 'async_trait,
    Self: Send + 'async_trait, 
[src]

Loading content...

Implementations on Foreign Types

impl<T: TwitchToken + Send> TwitchToken for Box<T>[src]

fn token_type() -> BearerTokenType[src]

fn client_id(&self) -> &ClientId[src]

fn token(&self) -> &AccessToken[src]

fn login(&self) -> Option<&str>[src]

fn user_id(&self) -> Option<&str>[src]

fn refresh_token<'life0, 'async_trait, RE, C, F>(
    &'life0 mut self,
    http_client: C
) -> Pin<Box<dyn Future<Output = Result<(), RefreshTokenError<RE>>> + Send + 'async_trait>> where
    Self: Sized,
    RE: Error + Send + Sync + 'static,
    C: FnOnce(HttpRequest) -> F + Send,
    F: Future<Output = Result<HttpResponse, RE>> + Send,
    RE: 'async_trait,
    C: 'async_trait,
    F: 'async_trait,
    'life0: 'async_trait,
    Self: 'async_trait, 
[src]

fn expires_in(&self) -> Duration[src]

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

Loading content...

Implementors

impl TwitchToken for AppAccessToken[src]

fn token_type() -> BearerTokenType[src]

fn client_id(&self) -> &ClientId[src]

fn token(&self) -> &AccessToken[src]

fn login(&self) -> Option<&str>[src]

fn user_id(&self) -> Option<&str>[src]

fn refresh_token<'life0, 'async_trait, RE, C, F>(
    &'life0 mut self,
    http_client: C
) -> Pin<Box<dyn Future<Output = Result<(), RefreshTokenError<RE>>> + Send + 'async_trait>> where
    RE: Error + Send + Sync + 'static,
    C: FnOnce(HttpRequest) -> F + Send,
    F: Future<Output = Result<HttpResponse, RE>> + Send,
    RE: 'async_trait,
    C: 'async_trait,
    F: 'async_trait,
    'life0: 'async_trait,
    Self: 'async_trait, 
[src]

fn expires_in(&self) -> Duration[src]

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

impl TwitchToken for UserToken[src]

fn token_type() -> BearerTokenType[src]

fn client_id(&self) -> &ClientId[src]

fn token(&self) -> &AccessToken[src]

fn login(&self) -> Option<&str>[src]

fn user_id(&self) -> Option<&str>[src]

fn refresh_token<'life0, 'async_trait, RE, C, F>(
    &'life0 mut self,
    http_client: C
) -> Pin<Box<dyn Future<Output = Result<(), RefreshTokenError<RE>>> + Send + 'async_trait>> where
    Self: Sized,
    RE: Error + Send + Sync + 'static,
    C: FnOnce(HttpRequest) -> F + Send,
    F: Future<Output = Result<HttpResponse, RE>> + Send,
    RE: 'async_trait,
    C: 'async_trait,
    F: 'async_trait,
    'life0: 'async_trait,
    Self: 'async_trait, 
[src]

fn expires_in(&self) -> Duration[src]

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

Loading content...