MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / parse_jwt_exp_ms

Function parse_jwt_exp_ms

crates/openshell-core/src/grpc_client.rs:441–452  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

439/// Returns the expiry in milliseconds since the Unix epoch, or `None` if
440/// the token is not a parseable JWT.
441fn 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)]
455mod auth_tests {

Callers 1

compute_refresh_delayFunction · 0.85

Calls 2

nextMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected