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, C>(
&mut self,
http_client: &'a C,
) -> impl Future<Output = Result<(), RefreshTokenError<<C as Client>::Error>>> + Send
where Self: Sized,
C: Client;
fn expires_in(&self) -> Duration;
fn scopes(&self) -> &[Scope];
// Provided methods
fn is_elapsed(&self) -> bool { ... }
fn validate_token<'a, C>(
&self,
http_client: &'a C,
) -> impl Future<Output = Result<ValidatedToken, ValidationError<<C as Client>::Error>>> + Send
where Self: Sized,
C: Client { ... }
fn revoke_token<'a, C>(
self,
http_client: &'a C,
) -> impl Future<Output = Result<(), RevokeTokenError<<C as Client>::Error>>> + Send
where Self: Sized + Send,
C: Client { ... }
}Expand description
Trait for twitch tokens to get fields and generalize over AppAccessToken and UserToken
Required Methods§
Sourcefn token_type() -> BearerTokenType
fn token_type() -> BearerTokenType
Get the type of token.
Sourcefn client_id(&self) -> &ClientId
fn client_id(&self) -> &ClientId
Client ID associated with the token. Twitch requires this in all helix API calls
Sourcefn token(&self) -> &AccessToken
fn token(&self) -> &AccessToken
Get the AccessToken for authenticating
§Example
use twitch_oauth2::TwitchToken;
println!("token: {}", user_token.token().secret());Sourcefn login(&self) -> Option<&UserNameRef>
fn login(&self) -> Option<&UserNameRef>
Get the username associated to this token
Sourcefn refresh_token<'a, C>(
&mut self,
http_client: &'a C,
) -> impl Future<Output = Result<(), RefreshTokenError<<C as Client>::Error>>> + Send
Available on crate feature client only.
fn refresh_token<'a, C>( &mut self, http_client: &'a C, ) -> impl Future<Output = Result<(), RefreshTokenError<<C as Client>::Error>>> + Send
client only.Refresh this token, changing the token to a newer one
Sourcefn expires_in(&self) -> Duration
fn expires_in(&self) -> Duration
Get current lifetime of token.
Provided Methods§
Sourcefn is_elapsed(&self) -> bool
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?;
}Sourcefn validate_token<'a, C>(
&self,
http_client: &'a C,
) -> impl Future<Output = Result<ValidatedToken, ValidationError<<C as Client>::Error>>> + Send
Available on crate feature client only.
fn validate_token<'a, C>( &self, http_client: &'a C, ) -> impl Future<Output = Result<ValidatedToken, ValidationError<<C as Client>::Error>>> + Send
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
Sourcefn revoke_token<'a, C>(
self,
http_client: &'a C,
) -> impl Future<Output = Result<(), RevokeTokenError<<C as Client>::Error>>> + Send
Available on crate feature client only.
fn revoke_token<'a, C>( self, http_client: &'a C, ) -> impl Future<Output = Result<(), RevokeTokenError<<C as Client>::Error>>> + Send
client only.Revoke the token. See https://dev.twitch.tv/docs/authentication/revoke-tokens
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>
impl<T: TwitchToken + Send> TwitchToken for Box<T>
fn token_type() -> BearerTokenType
fn client_id(&self) -> &ClientId
fn token(&self) -> &AccessToken
fn login(&self) -> Option<&UserNameRef>
fn user_id(&self) -> Option<&UserIdRef>
Source§async fn refresh_token<'a, C>(
&mut self,
http_client: &'a C,
) -> Result<(), RefreshTokenError<<C as Client>::Error>>
async fn refresh_token<'a, C>( &mut self, http_client: &'a C, ) -> Result<(), RefreshTokenError<<C as Client>::Error>>
client only.