pub struct Jwt { /* private fields */ }Expand description
The JWT plugin: .plugin(Jwt::new()).
Implementations§
Source§impl Jwt
impl Jwt
pub fn new() -> Self
Sourcepub fn algorithm(self, alg: JwtAlgorithm) -> Self
pub fn algorithm(self, alg: JwtAlgorithm) -> Self
The algorithm of new keys (default EdDSA). Switching mints a key of the new algorithm on the next signing; tokens signed by the old keys keep verifying.
Sourcepub fn issuer(self, issuer: impl Into<String>) -> Self
pub fn issuer(self, issuer: impl Into<String>) -> Self
The iss of every token (default: the base URL).
Sourcepub fn audience(self, audience: impl Into<String>) -> Self
pub fn audience(self, audience: impl Into<String>) -> Self
The aud of every token (default: the base URL).
Sourcepub fn expiration_time(self, ttl: Duration) -> Self
pub fn expiration_time(self, ttl: Duration) -> Self
How long tokens are valid (default 15 minutes).
Sourcepub fn rotation_interval(self, interval: Duration) -> Self
pub fn rotation_interval(self, interval: Duration) -> Self
Keys expire this long after they’re created, and the next signing creates a new one
(default: keys never expire). Better Auth’s jwks.rotationInterval.
Sourcepub fn grace_period(self, grace: Duration) -> Self
pub fn grace_period(self, grace: Duration) -> Self
How long an expired key stays in the JWKS (default 30 days). Keep it longer than
expiration_time. Better Auth’s jwks.gracePeriod.
Sourcepub fn disable_jwt_header(self) -> Self
pub fn disable_jwt_header(self) -> Self
Stops /get-session from signing a token into set-auth-jwt on every call. Better
Auth’s disableSettingJwtHeader.
Sourcepub fn define_payload<F, Fut>(self, define: F) -> Self
pub fn define_payload<F, Fut>(self, define: F) -> Self
The claims a session’s token carries instead of the user. sub is always the user id
and iat, exp, iss and aud are added unless the claims set them. Better
Auth’s jwt.definePayload.
let jwt = Jwt::new().define_payload(|session| async move {
let mut claims = serde_json::Map::new();
claims.insert("email".into(), session.user.email.clone().into());
claims.insert("role".into(), "member".into());
Ok(claims)
});Trait Implementations§
Source§impl Plugin for Jwt
impl Plugin for Jwt
Source§const ID: &'static str = "jwt"
const ID: &'static str = "jwt"
Source§type Requires = ()
type Requires = ()
(), (Organization,).Source§type UserFields = ()
type UserFields = ()
user; () for none.Source§type SessionFields = ()
type SessionFields = ()
session; () for none.Source§fn schema(&self, schema: &mut SchemaBuilder)
fn schema(&self, schema: &mut SchemaBuilder)
schema.model::<M>()) or columns. UserFields and SessionFields are
added automatically.