Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/azure web token #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
25 changes: 8 additions & 17 deletions src/keyset.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{convert::TryFrom, convert::TryInto};
use std::time::{Duration, SystemTime};
use std::{convert::TryFrom, convert::TryInto};

use base64::Engine;
use jwt_simple::prelude::*;
Expand All @@ -11,7 +11,7 @@ use crate::error::*;

#[derive(Debug, Deserialize)]
pub struct JWK {
pub alg: String,
pub alg: Option<String>,
pub kid: String,
pub kty: String,
pub e: Option<String>,
Expand Down Expand Up @@ -65,9 +65,7 @@ impl JwtKey {

pub fn decoding_key(&self) -> Result<RSAPublicKeyInputs, Error> {
match &self.kind {
JwtKeyKind::RSA(key_inputs) => {
Ok(key_inputs.clone())
}
JwtKeyKind::RSA(key_inputs) => Ok(key_inputs.clone()),
JwtKeyKind::UnsupportedKty(kty) => {
tracing::debug!("Unsupported key type: {}", kty);
Err(err("Unsupported key type", Type::Key))
Expand All @@ -85,6 +83,7 @@ impl TryFrom<JWK> for JwtKey {
("RSA", _, _) => return Err(err("RSA key missing parameters", Type::Certificate)),
(_, _, _) => JwtKeyKind::UnsupportedKty(kty.clone()),
};
let alg = alg.unwrap_or("RS256".to_owned());
Ok(JwtKey { kty, kid, alg: Some(alg), kind })
}
}
Expand Down Expand Up @@ -245,17 +244,11 @@ impl KeyStore {
JwtKeyKind::RSA(key_inputs) => {
let n = base64::engine::general_purpose::URL_SAFE_NO_PAD.decode(key_inputs.n.as_str()).map_err(|e| {
tracing::debug!("failed to decode n: {}", e);
Error {
msg: "failed to decode n",
typ: Type::Key,
}
Error { msg: "failed to decode n", typ: Type::Key }
})?;
let e = base64::engine::general_purpose::URL_SAFE_NO_PAD.decode(key_inputs.e.as_str()).map_err(|e| {
tracing::debug!("failed to decode e: {}", e);
Error {
msg: "failed to decode e",
typ: Type::Key,
}
Error { msg: "failed to decode e", typ: Type::Key }
})?;
let alg = if let Some(alg) = &key.alg {
alg
Expand Down Expand Up @@ -297,15 +290,13 @@ impl KeyStore {
})?;
Ok(data)
}
_ => {
Err(err("Unsupported algorithm", Type::Key))
}
_ => Err(err("Unsupported algorithm", Type::Key)),
}
}
JwtKeyKind::UnsupportedKty(kty) => {
tracing::error!("Unsupported key type: {}", kty);
Err(err("Unsupported key type", Type::Key))
},
}
}?;
Ok(data)
}
Expand Down