Skip to main content

jwt_ttl

Function jwt_ttl 

Source
pub fn jwt_ttl(token: &str) -> Option<Duration>
Expand description

Lifetime from the JWT payload (exp - iat), if the token is a readable JWT.

The signature is not checked and the token is not validated. None when the token is not a JWT, the claims are missing, or exp is not after iat.

§Examples

use std::time::Duration;
use brokapi_finam_protocol::auth::jwt_ttl;

// Header {"alg":"none"}, payload {"iat":1000,"exp":1900}.
let token = "eyJhbGciOiJub25lIn0.eyJpYXQiOjEwMDAsImV4cCI6MTkwMH0.sig";
assert_eq!(jwt_ttl(token), Some(Duration::from_secs(900)));
assert_eq!(jwt_ttl("opaque-token"), None);