Extract `preferred_username` from a JWT payload without signature verification.
(token: &str)
| 1274 | |
| 1275 | /// Extract `preferred_username` from a JWT payload without signature verification. |
| 1276 | fn jwt_preferred_username(token: &str) -> Option<String> { |
| 1277 | let payload = token.split('.').nth(1)?; |
| 1278 | let decoded = |
| 1279 | base64::Engine::decode(&base64::engine::general_purpose::URL_SAFE_NO_PAD, payload).ok()?; |
| 1280 | let claims: serde_json::Value = serde_json::from_slice(&decoded).ok()?; |
| 1281 | claims |
| 1282 | .get("preferred_username") |
| 1283 | .and_then(|v| v.as_str()) |
| 1284 | .map(String::from) |
| 1285 | } |
| 1286 | |
| 1287 | /// Clear stored authentication credentials for a gateway. |
| 1288 | pub fn gateway_logout(name: &str) -> Result<()> { |
no test coverage detected