mirror of
https://github.com/TECHNOFAB11/jwt-authorizer.git
synced 2025-12-11 23:50:07 +01:00
chore: fmt
This commit is contained in:
parent
ec02b70a99
commit
d8fb138d46
8 changed files with 86 additions and 78 deletions
|
|
@ -28,11 +28,13 @@ async fn main() {
|
|||
|
||||
// First let's create an authorizer builder from a JWKS Endpoint
|
||||
// User is a struct deserializable from JWT claims representing the authorized user
|
||||
let jwt_auth: JwtAuthorizer<User> = JwtAuthorizer::
|
||||
from_jwks_url("http://localhost:3000/oidc/jwks")
|
||||
// .no_refresh()
|
||||
.refresh(Refresh {strategy: RefreshStrategy::Interval, ..Default::default()})
|
||||
.check(claim_checker);
|
||||
let jwt_auth: JwtAuthorizer<User> = JwtAuthorizer::from_jwks_url("http://localhost:3000/oidc/jwks")
|
||||
// .no_refresh()
|
||||
.refresh(Refresh {
|
||||
strategy: RefreshStrategy::Interval,
|
||||
..Default::default()
|
||||
})
|
||||
.check(claim_checker);
|
||||
|
||||
let oidc = Router::new()
|
||||
.route("/authorize", post(oidc_provider::authorize))
|
||||
|
|
|
|||
|
|
@ -46,9 +46,7 @@ struct JwkSet {
|
|||
pub async fn jwks() -> Json<Value> {
|
||||
// let mut ksmap = serde_json::Map::new();
|
||||
|
||||
let mut kset = JwkSet {
|
||||
keys: Vec::<Jwk>::new(),
|
||||
};
|
||||
let mut kset = JwkSet { keys: Vec::<Jwk>::new() };
|
||||
|
||||
let keypair = RsaKeyPair::from_pem(include_bytes!("../../../config/jwtRS256.key")).unwrap();
|
||||
let mut pk = keypair.to_jwk_public_key();
|
||||
|
|
@ -64,19 +62,14 @@ pub async fn jwks() -> Json<Value> {
|
|||
pk.set_key_use("sig");
|
||||
kset.keys.push(pk);
|
||||
|
||||
let keypair =
|
||||
EcKeyPair::from_pem(include_bytes!("../../../config/ec256-private.pem"), Some(EcCurve::P256)).unwrap();
|
||||
let keypair = EcKeyPair::from_pem(include_bytes!("../../../config/ec256-private.pem"), Some(EcCurve::P256)).unwrap();
|
||||
let mut pk = keypair.to_jwk_public_key();
|
||||
pk.set_key_id("key-ec");
|
||||
pk.set_algorithm("ES256");
|
||||
pk.set_key_use("sig");
|
||||
kset.keys.push(pk);
|
||||
|
||||
let keypair = EcKeyPair::from_pem(
|
||||
include_bytes!("../../../config/private_ecdsa_key.pem"),
|
||||
Some(EcCurve::P256),
|
||||
)
|
||||
.unwrap();
|
||||
let keypair = EcKeyPair::from_pem(include_bytes!("../../../config/private_ecdsa_key.pem"), Some(EcCurve::P256)).unwrap();
|
||||
let mut pk = keypair.to_jwk_public_key();
|
||||
pk.set_key_id("ec01");
|
||||
pk.set_algorithm("ES256");
|
||||
|
|
@ -225,8 +218,8 @@ where
|
|||
let TypedHeader(Authorization(bearer)) = TypedHeader::<Authorization<Bearer>>::from_request_parts(parts, state)
|
||||
.await
|
||||
.map_err(|_| AuthError::InvalidToken)?;
|
||||
let token_data = decode::<Claims>(bearer.token(), &KEYS.decoding, &Validation::default())
|
||||
.map_err(|_| AuthError::InvalidToken)?;
|
||||
let token_data =
|
||||
decode::<Claims>(bearer.token(), &KEYS.decoding, &Validation::default()).map_err(|_| AuthError::InvalidToken)?;
|
||||
|
||||
Ok(token_data.claims)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue