pub struct KickOAuth { /* private fields */ }Expand description
Holds OAuth credentials and client for Kick.com
Implementations§
Source§impl KickOAuth
impl KickOAuth
Sourcepub fn from_env() -> Result<Self, Box<dyn Error>>
pub fn from_env() -> Result<Self, Box<dyn Error>>
Creates a new OAuth client by loading credentials from environment variables
Required env vars:
- KICK_CLIENT_ID
- KICK_CLIENT_SECRET
- KICK_REDIRECT_URI
Sourcepub fn from_env_server() -> Result<Self, Box<dyn Error>>
pub fn from_env_server() -> Result<Self, Box<dyn Error>>
Creates an OAuth client for server-to-server use (App Access Tokens only)
Only requires KICK_CLIENT_ID and KICK_CLIENT_SECRET env vars. No redirect URI needed since client credentials flow has no user interaction.
Generates the authorization URL that users should visit
Pass the scopes you need (must match what you configured in your Kick app)
Returns (auth_url, csrf_token, pkce_verifier)
- auth_url: The URL to send the user to
- csrf_token: Save this! You’ll verify it matches when they return
- pkce_verifier: REQUIRED! Pass this to exchange_code() later
Sourcepub async fn get_app_access_token(
&self,
) -> Result<OAuthTokenResponse, Box<dyn Error>>
pub async fn get_app_access_token( &self, ) -> Result<OAuthTokenResponse, Box<dyn Error>>
Request an App Access Token using the client credentials grant
This is a server-to-server flow that doesn’t require user interaction. The returned token can only access publicly available data.
Note: The response will not include a refresh_token — just request
a new app access token when the current one expires.
let oauth = kick_api::KickOAuth::from_env_server()?;
let token = oauth.get_app_access_token().await?;
let client = kick_api::KickApiClient::with_token(token.access_token);Sourcepub async fn exchange_code(
&self,
code: String,
pkce_verifier: PkceCodeVerifier,
) -> Result<OAuthTokenResponse, Box<dyn Error>>
pub async fn exchange_code( &self, code: String, pkce_verifier: PkceCodeVerifier, ) -> Result<OAuthTokenResponse, Box<dyn Error>>
Exchanges the authorization code for an access token
After the user authorizes, Kick redirects to your callback with a code parameter.
Pass that code AND the pkce_verifier from get_authorization_url() to this function.
Returns an OAuthTokenResponse with access_token, refresh_token, expires_in, etc.
Sourcepub async fn refresh_token(
&self,
refresh_token: &str,
) -> Result<OAuthTokenResponse, Box<dyn Error>>
pub async fn refresh_token( &self, refresh_token: &str, ) -> Result<OAuthTokenResponse, Box<dyn Error>>
Refresh an access token using a refresh token
When your access token expires, use the refresh token from the original
exchange_code() response to get a new one.
§Parameters
refresh_token: The refresh token from a previous token response