use base64ct::{Base64UrlUnpadded, Encoding};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone)]
pub struct JsonWebToken {
pub header: Header,
pub claims: Claims,
}
#[derive(Deserialize, Clone, Debug, Serialize)]
pub struct Header {
pub alg: String,
pub typ: String,
pub kid: String,
pub jku: String,
}
#[derive(Deserialize, Clone, Debug, Serialize)]
pub struct Claims {
pub jti: String,
pub iss: String,
pub exp: u64,
pub iat: u64,
pub sub: String,
pub aud: String,
pub scopes: String,
}
impl JsonWebToken {
pub fn get_key_details(jws: String) -> Option<(String, String)> {
let header = jws.split('.').next()?;
let header = Base64UrlUnpadded::decode_vec(header).ok()?;
let header: Header = serde_json::from_slice(&header).ok()?;
Some((header.jku, header.kid))
}
}