Skip to content

Commit

Permalink
Remove id deserialize hack from libiam
Browse files Browse the repository at this point in the history
  • Loading branch information
smrtrfszm committed Jul 29, 2024
1 parent c3fa9a4 commit f6fa4ae
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions libiam/src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
};
use iam_common::{keys::jwt::Claims, Id};
use jsonwebtoken::{Algorithm, DecodingKey, Validation};
use std::sync::Arc;
use std::{str::FromStr, sync::Arc};

#[derive(Debug)]
pub struct UserInner {
Expand Down Expand Up @@ -48,31 +48,21 @@ impl User {

let api = iam.inner.api.with_token(token.clone());

// TODO: this should be done with `Jwt::get_claims()`
let claims =
jsonwebtoken::decode::<Claims>(token.as_str(), &DecodingKey::from_secret(&[]), &{
let mut v = Validation::new(Algorithm::EdDSA);
v.insecure_disable_signature_validation();
v.set_audience(&["https://verseghy-gimnazium.net"]);
v
})
.unwrap()
.claims;

Ok(Self {
inner: Arc::new(UserInner {
token: token.clone(),
id: serde_json::from_str::<Id>(
format!(
// HACK: impl FromStr
"\"{}\"",
jsonwebtoken::decode::<Claims>(
token.as_str(),
&DecodingKey::from_secret(&[]),
&{
let mut v = Validation::new(Algorithm::RS256);
v.insecure_disable_signature_validation();
v.set_audience(&["https://verseghy-gimnazium.net"]);
v
},
)
.unwrap()
.claims
.sub
.as_str()
)
.as_str(),
)
.unwrap(),
id: Id::from_str(&claims.sub)?,
_api: api,
}),
})
Expand Down

0 comments on commit f6fa4ae

Please sign in to comment.