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
impl AppAccessToken
Sourcepub 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
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
Sourcepub 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.
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,
client
only.Sourcepub fn from_response(
response: TwitchTokenResponse,
client_id: impl Into<ClientId>,
client_secret: impl Into<ClientSecret>,
) -> AppAccessToken
pub fn from_response( response: TwitchTokenResponse, client_id: impl Into<ClientId>, client_secret: impl Into<ClientSecret>, ) -> AppAccessToken
Assemble token from twitch responses.
Sourcepub 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.
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,
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?;
Sourcepub fn get_app_access_token_request(
client_id: &ClientIdRef,
client_secret: &ClientSecretRef,
scopes: Vec<Scope>,
) -> Request<Vec<u8>>
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
impl Clone for AppAccessToken
Source§fn clone(&self) -> AppAccessToken
fn clone(&self) -> AppAccessToken
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for AppAccessToken
impl Debug for AppAccessToken
Source§impl TwitchToken for AppAccessToken
impl TwitchToken for AppAccessToken
Source§fn token_type() -> BearerTokenType
fn token_type() -> BearerTokenType
Source§fn client_id(&self) -> &ClientId
fn client_id(&self) -> &ClientId
Source§fn token(&self) -> &AccessToken
fn token(&self) -> &AccessToken
Source§fn login(&self) -> Option<&UserNameRef>
fn login(&self) -> Option<&UserNameRef>
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,
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,
client
only.Source§fn expires_in(&self) -> Duration
fn expires_in(&self) -> Duration
Source§fn is_elapsed(&self) -> bool
fn is_elapsed(&self) -> bool
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>>
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>>
client
only.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>>
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>>
client
only.Auto Trait Implementations§
impl Freeze for AppAccessToken
impl RefUnwindSafe for AppAccessToken
impl Send for AppAccessToken
impl Sync for AppAccessToken
impl Unpin for AppAccessToken
impl UnwindSafe for AppAccessToken
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)