Expand description
OAuth2 for Twitch endpoints
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]`
§About
§Scopes
The library contains all known twitch oauth2 scopes in Scope
.
§User Access Tokens
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
You can also use the newer OAuth device code flow with DeviceUserTokenBuilder
.
§App access token
Similar to UserToken
, a token with authorization as the twitch application can be created with
AppAccessToken::get_app_access_token
.
§HTTP Requests
To enable client features with a supported http library, enable the http library feature in twitch_oauth2
, like twitch_oauth2 = { features = ["reqwest"], version = "0.15.2" }
.
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
Re-exports§
pub use types::AccessToken;
pub use types::ClientId;
pub use types::ClientSecret;
pub use types::CsrfToken;
pub use types::RefreshToken;
pub use url;
Modules§
- client
client
- Provides different http clients
- id
- Representation of oauth2 flow in
id.twitch.tv
- scopes
- Module for all possible scopes in twitch.
- tokens
- Twitch token types
- types
- Types used in OAUTH2 flow.
Macros§
Structs§
- AppAccess
Token - An App Access Token from the OAuth client credentials flow
- Device
User Token Builder - Builder for OAuth device code flow
- Implicit
User Token Builder - Builder for OAuth implicit code flow
- User
Token - An User Token from the OAuth implicit code flow or OAuth authorization code flow
- User
Token Builder - Builder for OAuth authorization code flow
- Validated
Token - Token validation returned from
https://id.twitch.tv/oauth2/validate
Enums§
- Request
Parse Error - Errors from parsing responses
- Scope
- Scopes for twitch.
- Validator
- A validator is a way to check if an array of scopes matches a predicate.
Statics§
- AUTH_
URL - Authorization URL (
https://id.twitch.tv/oauth2/authorize
) forid.twitch.tv
- DEVICE_
URL - Device URL (
https://id.twitch.tv/oauth2/device
) forid.twitch.tv
- REVOKE_
URL - Revokation URL (
https://id.twitch.tv/oauth2/revoke
) forid.twitch.tv
- TOKEN_
URL - Token URL (
https://id.twitch.tv/oauth2/token
) forid.twitch.tv
- VALIDATE_
URL - Validation URL (
https://id.twitch.tv/oauth2/validate
) forid.twitch.tv
Traits§
- Twitch
Token - Trait for twitch tokens to get fields and generalize over AppAccessToken and UserToken