Decode a JWT and return the module id. IMPORTANT: This function does not validate the JWT, it only obtains the module id from the claims.
(jwt: Jwt)
| 360 | /// Decode a JWT and return the module id. IMPORTANT: This function does not |
| 361 | /// validate the JWT, it only obtains the module id from the claims. |
| 362 | pub fn decode_jwt(jwt: Jwt) -> eyre::Result<ModuleId> { |
| 363 | let mut validation = jsonwebtoken::Validation::default(); |
| 364 | validation.insecure_disable_signature_validation(); |
| 365 | |
| 366 | let module = jsonwebtoken::decode::<JwtClaims>( |
| 367 | jwt.as_str(), |
| 368 | &jsonwebtoken::DecodingKey::from_secret(&[]), |
| 369 | &validation, |
| 370 | )? |
| 371 | .claims |
| 372 | .module |
| 373 | .into(); |
| 374 | |
| 375 | Ok(module) |
| 376 | } |
| 377 | |
| 378 | /// Validate a JWT with the given secret |
| 379 | pub fn validate_jwt(jwt: Jwt, secret: &str) -> eyre::Result<()> { |
no outgoing calls