Create a JWT for the given module id with expiration
(module_id: &ModuleId, secret: &str)
| 345 | |
| 346 | /// Create a JWT for the given module id with expiration |
| 347 | pub fn create_jwt(module_id: &ModuleId, secret: &str) -> eyre::Result<Jwt> { |
| 348 | jsonwebtoken::encode( |
| 349 | &jsonwebtoken::Header::default(), |
| 350 | &JwtClaims { |
| 351 | module: module_id.to_string(), |
| 352 | exp: jsonwebtoken::get_current_timestamp() + SIGNER_JWT_EXPIRATION, |
| 353 | }, |
| 354 | &jsonwebtoken::EncodingKey::from_secret(secret.as_ref()), |
| 355 | ) |
| 356 | .map_err(Into::into) |
| 357 | .map(Jwt::from) |
| 358 | } |
| 359 | |
| 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. |
no outgoing calls