Expand description
OAuth 2.0 authorization client for the Chzzk API.
Handles the authorization code flow.
§Quick Start
use std::str::FromStr;
use tongbal_oauth::{ClientId, ClientSecret, RedirectUrl, TongbalOauth};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let oauth = TongbalOauth::new(
ClientId::from("client_id"),
ClientSecret::from("client_secret"),
RedirectUrl::from_str("http://localhost:3000/auth/callback")?,
);
let auth_url = oauth.auth_url();
println!("Visit: {}", auth_url);
Ok(())
}§Handling OAuth Callbacks
use tongbal_oauth::{AuthCallback, Error, TongbalOauth};
async fn handle_callback(
oauth: &TongbalOauth,
callback: AuthCallback,
) -> Result<(), Error> {
let token = oauth
.exchange_code(callback.code, callback.state)
.await?;
Ok(())
}§Token Management
§Refresh
let new_token = oauth.refresh_token(refresh_token).await?;§Revocation
Both AccessToken and RefreshToken can be revoked.
oauth.revoke_token(access_token).await?;
oauth.revoke_token(refresh_token).await?;§HTTP Client
A suitable HTTP client for authorization is used by default.
If customization is needed, see client::setup.
Modules§
Structs§
- Access
Token - Auth
Callback - AuthUrl
- Authorization
Code - Client
Id - Client
Secret - Redirect
Url - Refresh
Token - Response
- Revocation
Url - Token
- Token
Url - Tongbal
Oauth