twitch_oauth2::tokens

Struct AppAccessToken

Source
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<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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>,

Source§

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