pub struct Claims {
pub iss: String,
pub sub: String,
pub aud: String,
pub exp: Option<u64>,
pub nbf: u64,
pub iat: u64,
}Expand description
Represents registered JSON Web Token Claims. https://tools.ietf.org/html/rfc7519#section-4.1
Fields§
§iss: StringIssuer. Identifies the principal that issued the JWT. The processing of this claim is generally application specific.
sub: StringSubject. Identifies the principal that is the subject of the JWT. The claims in a JWT are normally statements about the subject. The subject value MUST either be scoped to be locally unique in the context of the issuer or be globally unique. The processing of this claim is generally application specific.
aud: StringAudience. Identifies the recipients that the JWT is intended for. Each principal intended to process the JWT MUST identify itself with a value in the audience claim. If the principal processing the claim does not identify itself with a value in the “aud” claim when this claim is present, then the JWT MUST be rejected. The interpretation of audience values is generally application specific.
exp: Option<u64>Expiration Time. Identifies the expiration time on or after which the JWT MUST NOT be accepted for processing. The processing of the “exp” claim requires that the current date/time MUST be before the expiration date/time listed in the “exp” claim. Implementers MAY provide for some small leeway, usually no more than a few minutes, to account for clock skew.
nbf: u64Not Before. Identifies the time before which the JWT MUST NOT be accepted for processing. The processing of the “nbf” claim requires that the current date/time MUST be after or equal to the not-before date/time listed in the “nbf” claim. Implementers MAY provide for some small leeway, usually no more than a few minutes, to account for clock skew.
iat: u64Issued At. Identifies the time at which the JWT was issued. This claim can be used to determine the age of the JWT.
Implementations§
Source§impl Claims
impl Claims
Sourcepub fn new(
iss: impl Into<String>,
sub: impl Into<String>,
aud: impl Into<String>,
) -> Result<Self, Error>
pub fn new( iss: impl Into<String>, sub: impl Into<String>, aud: impl Into<String>, ) -> Result<Self, Error>
Creates a new set of claims.
Sourcepub fn expires_after(self, exp: u64) -> Result<Self, Error>
pub fn expires_after(self, exp: u64) -> Result<Self, Error>
Specify that this token will expire by providing an expiry timestamp.
Sourcepub fn expires_after_duration(self, dur: Duration) -> Result<Self, Error>
pub fn expires_after_duration(self, dur: Duration) -> Result<Self, Error>
Specify that this token will expire by providing a duration offset from issued time.
Sourcepub fn valid_after(self, nbf: u64) -> Result<Self, Error>
pub fn valid_after(self, nbf: u64) -> Result<Self, Error>
Specify that this token is valid after the given timestamp.
Sourcepub fn valid_after_duration(self, dur: Duration) -> Result<Self, Error>
pub fn valid_after_duration(self, dur: Duration) -> Result<Self, Error>
Specify when this token becomes valid by providing a duration offset from issued time.
Sourcepub fn expiry(&self) -> Option<u64>
pub fn expiry(&self) -> Option<u64>
Returns the expiration time of the JWT, if it has been specified.
Sourcepub fn not_before(&self) -> u64
pub fn not_before(&self) -> u64
Returns the “nbf” field of the JWT.