Skip to content

Commit

Permalink
read key from env
Browse files Browse the repository at this point in the history
  • Loading branch information
tizz98 committed Aug 13, 2023
1 parent 70900af commit af90a10
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,26 @@ struct AppState {

#[tokio::main]
async fn main() -> jwtk::Result<()> {
let key_path = match std::env::var("XQR_KEY_PATH") {
Ok(path) => path,
_ => "key.pub".to_string(),
let key = match std::env::var("XQR_KEY") {
Ok(pub_key) => {
println!("using key from env");
pub_key.as_bytes().to_vec()
}
_ => {
let key_path = match std::env::var("XQR_KEY_PATH") {
Ok(path) => path,
_ => "key.pub".to_string(),
};
println!("using key path {:?}", key_path);
std::fs::read(key_path)?
}
};
println!("using key path {:?}", key_path);
let k = std::fs::read(key_path)?;

let k = SomePublicKey::from_pem(&k)?;
let k = WithKid::new_with_thumbprint_id(k)?;
println!("using key {:?}", k);
let key = SomePublicKey::from_pem(&key)?;
let key = WithKid::new_with_thumbprint_id(key)?;
println!("using key {:?}", key);

let k_public_jwk = k.public_key_to_jwk()?;
let k_public_jwk = key.public_key_to_jwk()?;
let jwks = JwkSet {
keys: vec![k_public_jwk],
};
Expand Down

0 comments on commit af90a10

Please sign in to comment.