Struct twitch_oauth2::tokens::UserToken [−][src]
pub struct UserToken {
pub access_token: AccessToken,
pub login: String,
pub user_id: String,
pub refresh_token: Option<RefreshToken>,
pub never_expiring: bool,
// some fields omitted
}
Expand description
An User Token from the OAuth implicit code flow or OAuth authorization code flow
Used for requests that need an authenticated user. See also AppAccessToken
See UserToken::builder
for authenticating the user using the OAuth authorization code flow
.
Fields
access_token: AccessToken
The access token used to authenticate requests with
login: String
Username of user associated with this token
user_id: String
User ID of the user associated with this token
refresh_token: Option<RefreshToken>
The refresh token used to extend the life of this user token
never_expiring: bool
Token will never expire
This is only true for old client IDs, like https://twitchapps.com/tmi and others
Implementations
pub fn from_existing_unchecked(
access_token: impl Into<AccessToken>,
refresh_token: impl Into<Option<RefreshToken>>,
client_id: impl Into<ClientId>,
client_secret: impl Into<Option<ClientSecret>>,
login: String,
user_id: String,
scopes: Option<Vec<Scope>>,
expires_in: Option<Duration>
) -> UserToken
pub fn from_existing_unchecked(
access_token: impl Into<AccessToken>,
refresh_token: impl Into<Option<RefreshToken>>,
client_id: impl Into<ClientId>,
client_secret: impl Into<Option<ClientSecret>>,
login: String,
user_id: String,
scopes: Option<Vec<Scope>>,
expires_in: Option<Duration>
) -> UserToken
Assemble token without checks.
If expires_in
is None
, we’ll assume token.is_elapsed
is always false
pub async fn from_existing<'a, C>(
http_client: &'a C,
access_token: AccessToken,
refresh_token: impl Into<Option<RefreshToken>>,
client_secret: impl Into<Option<ClientSecret>>
) -> Result<UserToken, ValidationError<<C as Client<'a>>::Error>> where
C: Client<'a>,
pub async fn from_existing<'a, C>(
http_client: &'a C,
access_token: AccessToken,
refresh_token: impl Into<Option<RefreshToken>>,
client_secret: impl Into<Option<ClientSecret>>
) -> Result<UserToken, ValidationError<<C as Client<'a>>::Error>> where
C: Client<'a>,
Assemble token and validate it. Retrieves login
, client_id
and scopes
If the token is already expired, this function will fail to produce a UserToken
and return ValidationError::NotAuthorized
pub fn builder(
client_id: ClientId,
client_secret: ClientSecret,
redirect_url: Url
) -> UserTokenBuilder
pub fn builder(
client_id: ClientId,
client_secret: ClientSecret,
redirect_url: Url
) -> UserTokenBuilder
Create a UserTokenBuilder
to get a token with the OAuth Authorization Code
pub async fn mock_token<'a, C>(
http_client: &'a C,
client_id: ClientId,
client_secret: ClientSecret,
user_id: impl AsRef<str>,
scopes: Vec<Scope>
) -> Result<UserToken, UserTokenExchangeError<<C as Client<'a>>::Error>> where
C: Client<'a>,
pub async fn mock_token<'a, C>(
http_client: &'a C,
client_id: ClientId,
client_secret: ClientSecret,
user_id: impl AsRef<str>,
scopes: Vec<Scope>
) -> Result<UserToken, UserTokenExchangeError<<C as Client<'a>>::Error>> where
C: Client<'a>,
Set the client secret
Trait Implementations
Get the type of token.
Client ID associated with the token. Twitch requires this in all helix API calls
Get the AccessToken for authenticating Read more
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<'a>>::Error>>> + Send + 'async_trait>> where
Self: Sized,
C: Client<'a>,
'a: 'async_trait,
C: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
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<'a>>::Error>>> + Send + 'async_trait>> where
Self: Sized,
C: Client<'a>,
'a: 'async_trait,
C: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
Refresh this token, changing the token to a newer one
Get current lifetime of token.
Retrieve scopes attached to the token
Returns whether or not the token is expired. Read more
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<'a>>::Error>>> + Send + 'async_trait>> where
Self: Sized,
C: Client<'a>,
'a: 'async_trait,
C: 'async_trait,
'life0: 'async_trait,
Self: Sync + 'async_trait,
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<'a>>::Error>>> + Send + 'async_trait>> where
Self: Sized,
C: Client<'a>,
'a: 'async_trait,
C: '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 Read more
Revoke the token. See https://dev.twitch.tv/docs/authentication#revoking-access-tokens
Auto Trait Implementations
impl RefUnwindSafe for UserToken
impl UnwindSafe for UserToken
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more