Function github_oidc::validate_github_token

source ·
pub async fn validate_github_token(
    token: &str,
    jwks: Arc<RwLock<GithubJWKS>>,
    expected_audience: Option<&str>,
) -> Result<GitHubClaims>
Expand description

Validates a GitHub OIDC token.

This is a convenience wrapper around GithubJWKS::validate_github_token. It provides the same functionality but as a standalone function.

§Arguments

  • token - The GitHub OIDC token to validate.
  • jwks - An Arc<RwLock<GithubJWKS>> containing the JSON Web Key Set.
  • expected_audience - An optional expected audience for the token.

§Returns

Returns a Result<GitHubClaims> containing the validated claims if successful, or an error if validation fails.

§Examples

use std::sync::Arc;
use github_oidc::{GithubJWKS, validate_github_token, fetch_jwks};
use color_eyre::Result;

#[tokio::main]
async fn main() -> Result<()> {

    match validate_github_token(token, jwks, Some("https://github.com/your-username")).await {
        Ok(claims) => println!("Token validated successfully. Claims: {:?}", claims),
        Err(e) => eprintln!("Token validation failed: {}", e),
    }

    Ok(())
}