get_name

Function get_name 

Source
pub fn get_name(token: &str) -> Result<String, MantaError>
Expand description

Extract the name claim from a JWT token.

Returns "MISSING" if the claim is absent.

ยงExamples

use base64::prelude::*;
use manta_shared::common::jwt_ops::get_name;

// Build a minimal three-part JWT whose payload carries a `name` claim.
let payload = BASE64_URL_SAFE_NO_PAD.encode(r#"{"name":"Alice"}"#);
let token = format!("header.{}.sig", payload);

assert_eq!(get_name(&token).unwrap(), "Alice");

// Bearer prefix is tolerated.
let with_prefix = format!("Bearer {}", token);
assert_eq!(get_name(&with_prefix).unwrap(), "Alice");