gbr/shared/jwt

Jwt read only functions.

Types

A decoded JWT that can be read.

pub opaque type Jwt

Errors that can occur when attempting to decode a JWT from a String or read from a successfully decoded JWT string.

pub type JwtDecodeError {
  TokenEmpty
  HeaderEmpty
  HeaderInvalid
  PayloadEmpty
  PayloadInvalid
  ClaimEmpty
  ClaimInvalid(List(decode.DecodeError))
}

Constructors

  • TokenEmpty
  • HeaderEmpty
  • HeaderInvalid
  • PayloadEmpty
  • PayloadInvalid
  • ClaimEmpty
  • ClaimInvalid(List(decode.DecodeError))

Values

pub fn error(err: JwtDecodeError) -> String
pub fn from_string(raw: String) -> Result(Jwt, JwtDecodeError)

From string encoded jwt

pub fn get_audience(
  from jwt: Jwt,
) -> Result(String, JwtDecodeError)

Retrieve the aud from the JWT’s payload.

pub fn get_expiration(
  from jwt: Jwt,
) -> Result(Int, JwtDecodeError)

Retrieve the exp from the JWT’s payload.

pub fn get_issued_at(
  from jwt: Jwt,
) -> Result(Int, JwtDecodeError)

Retrieve the iat from the JWT’s payload.

pub fn get_issuer(
  from jwt: Jwt,
) -> Result(String, JwtDecodeError)

Retrieve the iss from the JWT’s payload.

pub fn get_jwt_id(
  from jwt: Jwt,
) -> Result(String, JwtDecodeError)

Retrieve the jti from the JWT’s payload.

pub fn get_not_before(
  from jwt: Jwt,
) -> Result(Int, JwtDecodeError)

Retrieve the nbf from the JWT’s payload.

pub fn get_payload_claim(
  from jwt: Jwt,
  claim claim: String,
  decoder decoder: decode.Decoder(a),
) -> Result(a, JwtDecodeError)

Retrieve and decode a claim from a JWT’s payload.

pub fn get_subject(
  from jwt: Jwt,
) -> Result(String, JwtDecodeError)

Retrieve the sub from the JWT’s payload.

pub fn to_string(in: Jwt) -> String

To string encoded jwt

Search Document