Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/crates_io_trustpub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ tracing = "=0.1.41"
[dev-dependencies]
bon = "=3.7.2"
claims = "=0.8.0"
clap = { version = "=4.5.48", features = ["derive", "env", "unicode", "wrap_help"] }
insta = { version = "=1.43.2", features = ["json", "redactions"] }
mockito = "=1.7.0"
serde_json = "=1.0.145"
Expand Down
62 changes: 62 additions & 0 deletions crates/crates_io_trustpub/examples/load_jwks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use clap::{Parser, ValueEnum};
use crates_io_trustpub::github::GITHUB_ISSUER_URL;
use crates_io_trustpub::keystore::load_jwks::load_jwks;
use reqwest::Client;

#[derive(Clone, Debug, ValueEnum)]
enum Provider {
#[value(name = "github")]
GitHub,
}

impl Provider {
fn issuer_url(&self) -> &'static str {
match self {
Provider::GitHub => GITHUB_ISSUER_URL,
}
}
}

#[derive(Parser)]
#[command(name = "load_jwks")]
#[command(about = "Load and display JWKS keys from OpenID Connect providers")]
struct Args {
/// The provider to load JWKS from
provider: Provider,
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let args = Args::parse();

let issuer_url = args.provider.issuer_url();

println!("Loading JWKS for provider: {:?}", args.provider);
println!("Issuer URL: {}", issuer_url);
println!();

let client = Client::new();

let jwks = load_jwks(&client, issuer_url).await?;
println!("Successfully loaded JWKS with {} keys:", jwks.keys.len());
println!();

for key in &jwks.keys {
let key_id = key.common.key_id.as_deref().unwrap_or("<none>");
println!("Key ID: {}", key_id);

if let Some(alg) = &key.common.key_algorithm {
println!("Algorithm: {:?}", alg);
}

if let Some(usage) = &key.common.public_key_use {
println!("Usage: {:?}", usage);
}

println!("Algorithm Parameters: {:?}", key.algorithm);

println!();
}

Ok(())
}
2 changes: 1 addition & 1 deletion crates/crates_io_trustpub/src/keystore/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod r#impl;
mod load_jwks;
pub mod load_jwks;

use async_trait::async_trait;
pub use r#impl::RealOidcKeyStore;
Expand Down