Struct twitch_oauth2::UserToken
source · [−]pub struct UserToken {
pub access_token: AccessToken,
pub login: UserName,
pub user_id: UserId,
pub refresh_token: Option<RefreshToken>,
pub never_expiring: bool,
/* private fields */
}
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: UserName
Username of user associated with this token
user_id: UserId
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
sourceimpl UserToken
impl UserToken
sourcepub 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: UserName,
user_id: UserId,
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: UserName,
user_id: UserId,
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
sourcepub 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
sourcepub 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
sourcepub 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>,
sourcepub fn set_secret(&mut self, secret: Option<ClientSecret>)
pub fn set_secret(&mut self, secret: Option<ClientSecret>)
Set the client secret
Trait Implementations
sourceimpl TwitchToken for UserToken
impl TwitchToken for UserToken
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 Read more
sourcefn login(&self) -> Option<&UserNameRef>
fn login(&self) -> Option<&UserNameRef>
Get the username associated to this token
sourcefn 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
sourcefn expires_in(&self) -> Duration
fn expires_in(&self) -> Duration
Get current lifetime of token.
sourcefn is_elapsed(&self) -> bool
fn is_elapsed(&self) -> bool
Returns whether or not the token is expired. Read more
sourcefn 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
sourcefn revoke_token<'a, 'async_trait, C>(
self,
http_client: &'a C
) -> Pin<Box<dyn Future<Output = Result<(), RevokeTokenError<<C as Client<'a>>::Error>>> + Send + 'async_trait>> where
Self: Sized,
C: Client<'a>,
'a: 'async_trait,
C: 'async_trait,
Self: Send + 'async_trait,
fn revoke_token<'a, 'async_trait, C>(
self,
http_client: &'a C
) -> Pin<Box<dyn Future<Output = Result<(), RevokeTokenError<<C as Client<'a>>::Error>>> + Send + 'async_trait>> where
Self: Sized,
C: Client<'a>,
'a: 'async_trait,
C: 'async_trait,
Self: Send + 'async_trait,
Revoke the token. See https://dev.twitch.tv/docs/authentication#revoking-access-tokens
Auto Trait Implementations
impl RefUnwindSafe for UserToken
impl Send for UserToken
impl Sync for UserToken
impl Unpin for UserToken
impl UnwindSafe for UserToken
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more