| Crates.io | twitch_oauth_token |
| lib.rs | twitch_oauth_token |
| version | 2.0.6 |
| created_at | 2024-02-29 10:31:36.040535+00 |
| updated_at | 2025-09-15 20:46:16.429949+00 |
| description | Type-safe Twitch OAuth 2.0 authentication library with CSRF protection and full scope support |
| homepage | |
| repository | https://github.com/m3idnotfree/twitch_oauth.git |
| max_upload_size | |
| id | 1157646 |
| size | 277,510 |
A Rust library for Twitch OAuth 2.0 authentication with compile-time safety and comprehensive scope support.
[dependencies]
twitch_oauth_token = "2"
tokio = { version = "1", features = ["full"] }
use twitch_oauth_token::TwitchOauth;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let oauth = TwitchOauth::new("client_id", "client_secret");
let resp = oauth.app_access_token().await?;
let token = resp.app_token().await?;
println!("App token: {}", token.access_token.secret());
println!("Expires in: {} seconds", token.expires_in);
Ok(())
}
use std::str::FromStr;
use twitch_oauth_token::{scope::ChatScopes, RedirectUrl, TwitchOauth};
fn main() {
let oauth = TwitchOauth::new("client_id", "client_secret")
.set_redirect_uri(RedirectUrl::from_str("http://example.com/auth/callback").unwrap());
let mut auth_request = oauth.authorization_url();
auth_request.scopes_mut().chat_api_as_user();
// Create authorization URL for the user to visit
let auth_url = auth_request.url();
println!("Visit: {}", auth_url);
}
use twitch_oauth_token::{OAuthCallbackQuery, TwitchOauth, UserAuth};
async fn handle_callback(
oauth: &TwitchOauth<UserAuth>,
oauth_callback: OAuthCallbackQuery,
) -> Result<(), twitch_oauth_token::Error> {
let response = oauth
.user_access_token(oauth_callback.code, oauth_callback.state)
.await?;
let token = response.user_token().await?;
println!("Access token: {}", token.access_token.secret());
println!("Refresh token: {}", token.refresh_token.secret());
println!("Scopes: {:?}", token.scope);
println!("Expires in: {} seconds", token.expires_in);
Ok(())
}
oneshot-server - Built-in development server for handling OAuth callbackstest - Testing utilities and mock server supportLicensed under the MIT license.