use twitch_oauth2::{tokens::errors::ValidationError, AccessToken, TwitchToken, UserToken};
// 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 = AccessToken::new("sometokenherewhichisvalidornot".to_string());
let token = UserToken::from_token(&client, token).await?;
println!("token: {:?}", token.token()); // prints `[redacted access token]`
The library contains all known twitch oauth2 scopes in Scope
.
For most basic use cases with user authorization, UserToken::from_token
will be your main way
to create user tokens in this library.
Things like UserTokenBuilder
can be used to create a token from scratch, via the OAuth authorization code flow
Similar to UserToken
, a token with authorization as the twitch application can be created with
AppAccessToken::get_app_access_token
.
To enable client features with a supported http library, enable the http library feature in twitch_oauth2
, like twitch_oauth2 = { features = ["reqwest"], version = "0.14.0" }
.
If you’re using twitch_api, you can use its HelixClient
instead of the underlying http client.
This library can be used without any specific http client library (like if you don’t want to use await
),
using methods like AppAccessToken::from_response
and AppAccessToken::get_app_access_token_request
or UserTokenBuilder::get_user_token_request
and UserToken::from_response
pub use types::AccessToken;
pub use types::ClientId;
pub use types::ClientSecret;
pub use types::CsrfToken;
pub use types::RefreshToken;
pub use url;
client
id.twitch.tv
https://id.twitch.tv/oauth2/validate
https://id.twitch.tv/oauth2/authorize
) for id.twitch.tv
https://id.twitch.tv/oauth2/revoke
) for id.twitch.tv
https://id.twitch.tv/oauth2/token
) for id.twitch.tv
https://id.twitch.tv/oauth2/validate
) for id.twitch.tv