pub struct AppAccessToken {
    pub access_token: AccessToken,
    pub refresh_token: Option<RefreshToken>,
    /* private fields */
}
Expand description

An App Access Token from the OAuth client credentials flow

Used for server-to-server requests. Use UserToken for requests that need to be in the context of an authenticated user.

In some contexts (i.e EventSub) an App Access Token can be used in the context of users that have authenticated the specific Client ID

Fields§

§access_token: AccessToken

The access token used to authenticate requests with

§refresh_token: Option<RefreshToken>

The refresh token used to extend the life of this user token

Implementations§

source§

impl AppAccessToken

source

pub fn from_existing_unchecked( access_token: AccessToken, refresh_token: impl Into<Option<RefreshToken>>, client_id: impl Into<ClientId>, client_secret: impl Into<ClientSecret>, scopes: Option<Vec<Scope>>, expires_in: Option<Duration> ) -> AppAccessToken

Assemble token without checks.

This is useful if you already have an app access token and want to use it with this library. Be careful however, as this function does not check if the token is valid or expired, nor if it is an app access token or user token.

§Notes

If expires_in is None, we’ll assume token.is_elapsed() == true

source

pub async fn from_existing<RE, C>( http_client: &C, access_token: AccessToken, refresh_token: impl Into<Option<RefreshToken>>, client_secret: ClientSecret ) -> Result<AppAccessToken, ValidationError<<C as Client>::Error>>
where C: Client,

Available on crate feature client only.

Assemble token and validate it. Retrieves client_id and scopes.

source

pub fn from_response( response: TwitchTokenResponse, client_id: impl Into<ClientId>, client_secret: impl Into<ClientSecret> ) -> AppAccessToken

Assemble token from twitch responses.

source

pub async fn get_app_access_token<C>( http_client: &C, client_id: ClientId, client_secret: ClientSecret, scopes: Vec<Scope> ) -> Result<AppAccessToken, AppAccessTokenError<<C as Client>::Error>>
where C: Client,

Available on crate feature client only.

Generate an app access token via OAuth client credentials flow

§Examples
use twitch_oauth2::{AccessToken, AppAccessToken};
// Make sure you enable the feature "reqwest" for twitch_oauth2 if you want to use reqwest
let client = reqwest::Client::builder()
    .redirect(reqwest::redirect::Policy::none())
    .build()?;
let token = AppAccessToken::get_app_access_token(
    &client,
    "my_client_id".into(),
    "my_client_secret".into(),
    vec![], // scopes
)
.await?;
source

pub fn get_app_access_token_request( client_id: &ClientIdRef, client_secret: &ClientSecretRef, scopes: Vec<Scope> ) -> Request<Vec<u8>>

Get the request for getting an app access token.

Parse with TwitchTokenResponse::from_response and AppAccessToken::from_response

Trait Implementations§

source§

impl Clone for AppAccessToken

source§

fn clone(&self) -> AppAccessToken

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for AppAccessToken

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl TwitchToken for AppAccessToken

source§

fn token_type() -> BearerTokenType

Get the type of token.
source§

fn client_id(&self) -> &ClientId

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

fn token(&self) -> &AccessToken

Get the AccessToken for authenticating Read more
source§

fn login(&self) -> Option<&UserNameRef>

Get the username associated to this token
source§

fn user_id(&self) -> Option<&UserIdRef>

Get the user id associated to this token
source§

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>::Error>>> + Send + 'async_trait>>
where C: Client + 'async_trait, Self: 'async_trait, 'a: 'async_trait, 'life0: 'async_trait,

Available on crate feature client only.
Refresh this token, changing the token to a newer one
source§

fn expires_in(&self) -> Duration

Get current lifetime of token.
source§

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

Retrieve scopes attached to the token
source§

fn is_elapsed(&self) -> bool

Returns whether or not the token is expired. Read more
source§

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>::Error>>> + Send + 'async_trait>>
where Self: Sized + Sync + 'async_trait, C: Client + 'async_trait, 'a: 'async_trait, 'life0: 'async_trait,

Available on crate feature client only.
Validate this token. Should be checked on regularly, according to https://dev.twitch.tv/docs/authentication/validate-tokens/ Read more
source§

fn revoke_token<'a, 'async_trait, C>( self, http_client: &'a C ) -> Pin<Box<dyn Future<Output = Result<(), RevokeTokenError<<C as Client>::Error>>> + Send + 'async_trait>>
where Self: Sized + Send + 'async_trait, C: Client + 'async_trait, 'a: 'async_trait,

Available on crate feature client only.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more