Decode the `exp` claim from a JWT without verifying its signature. Returns the expiry in milliseconds since the Unix epoch, or `None` if the token is not a parseable JWT.
(jwt: &str)
| 439 | /// Returns the expiry in milliseconds since the Unix epoch, or `None` if |
| 440 | /// the token is not a parseable JWT. |
| 441 | fn parse_jwt_exp_ms(jwt: &str) -> Option<i64> { |
| 442 | use base64::Engine; |
| 443 | let mut parts = jwt.splitn(3, '.'); |
| 444 | let _header = parts.next()?; |
| 445 | let payload_b64 = parts.next()?; |
| 446 | let decoded = base64::engine::general_purpose::URL_SAFE_NO_PAD |
| 447 | .decode(payload_b64) |
| 448 | .ok()?; |
| 449 | let value: serde_json::Value = serde_json::from_slice(&decoded).ok()?; |
| 450 | let exp_secs = value.get("exp")?.as_i64()?; |
| 451 | exp_secs.checked_mul(1000) |
| 452 | } |
| 453 | |
| 454 | #[cfg(test)] |
| 455 | mod auth_tests { |
no test coverage detected