Crate twitch_oauth2
source ·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
§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.13.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
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 - Representation of oauth2 flow in
id.twitch.tv
- Module for all possible scopes in twitch.
- Twitch token types
- Types used in OAUTH2 flow.
Macros§
- A validator is a way to check if a slice of scopes matches a predicate.
Structs§
- An App Access Token from the OAuth client credentials flow
- Builder for OAuth implicit code flow
- An User Token from the OAuth implicit code flow or OAuth authorization code flow
- Builder for OAuth authorization code flow
- Token validation returned from
https://id.twitch.tv/oauth2/validate
Enums§
- Errors from parsing responses
- Scopes for twitch.
- A validator is a way to check if an array of scopes matches a predicate.
Statics§
- Authorization URL (
https://id.twitch.tv/oauth2/authorize
) forid.twitch.tv
- Revokation URL (
https://id.twitch.tv/oauth2/revoke
) forid.twitch.tv
- Token URL (
https://id.twitch.tv/oauth2/token
) forid.twitch.tv
- Validation URL (
https://id.twitch.tv/oauth2/validate
) forid.twitch.tv
Traits§
- Trait for twitch tokens to get fields and generalize over AppAccessToken and UserToken