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>; 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 { ... } 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, { ... } 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, { ... } }
Expand description
Trait for twitch tokens to get fields and generalize over AppAccessToken and UserToken
Required methods
fn token_type() -> BearerTokenType
fn token_type() -> BearerTokenType
Get the type of token.
Client ID associated with the token. Twitch requires this in all helix API calls
fn token(&self) -> &AccessToken
fn token(&self) -> &AccessToken
Get the AccessToken for authenticating
Example
use twitch_oauth2::TwitchToken; println!("token: {}", user_token.token().secret().as_str());
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 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,
Refresh this token, changing the token to a newer one
fn expires_in(&self) -> Duration
fn expires_in(&self) -> Duration
Get current lifetime of token.
Provided methods
fn is_elapsed(&self) -> bool
fn is_elapsed(&self) -> bool
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?; }
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,
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,
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
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,
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,
Revoke the token. See https://dev.twitch.tv/docs/authentication#revoking-access-tokens
Implementations on Foreign Types
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,