zino_model::user

Trait JwtAuthService

Source
pub trait JwtAuthService<K = Uuid>
where Self: ModelAccessor<K> + ModelHelper<K>, K: Default + Display + FromStr + PartialEq + DeserializeOwned, <K as FromStr>::Err: Error + Send + 'static,
{ const ACCOUNT_FIELD: &'static str = "account"; const PASSWORD_FIELD: &'static str = "password"; const ROLE_FIELD: Option<&'static str> = _; const TENANT_ID_FIELD: Option<&'static str> = None; const LOGIN_AT_FIELD: Option<&'static str> = None; const LOGIN_IP_FIELD: Option<&'static str> = None; // Provided methods fn into_standard_claims(self) -> Map { ... } async fn generate_token(body: Map) -> Result<(K, Map), Error> { ... } async fn refresh_token(claims: &JwtClaims) -> Result<Map, Error> { ... } async fn verify_jwt_claims(claims: &JwtClaims) -> Result<bool, Error> { ... } async fn verify_identity(user_id: K, body: &Map) -> Result<Map, Error> { ... } }
Expand description

JWT authentication service.

Provided Associated Constants§

Source

const ACCOUNT_FIELD: &'static str = "account"

Account field name.

Source

const PASSWORD_FIELD: &'static str = "password"

Password field name.

Source

const ROLE_FIELD: Option<&'static str> = _

Role field name.

Source

const TENANT_ID_FIELD: Option<&'static str> = None

Tenant-ID field name.

Source

const LOGIN_AT_FIELD: Option<&'static str> = None

Login-at field name.

Source

const LOGIN_IP_FIELD: Option<&'static str> = None

Login-IP field name.

Provided Methods§

Source

fn into_standard_claims(self) -> Map

Consumes the user into standard claims without a sub field, which can be used to create a JwtClaims and generate an ID token. See the spec.

§Examples
use zino_auth::JwtClaims;
use zino_core::model::Model;
use zino_model::user::{JwtAuthService, User};
use zino_orm::ModelAccessor;

let user = User::new();
let subject = user.id().to_string();
let custom_data = user.into_standard_claims();
let claims = JwtClaims::with_data(subject, custom_data);
let id_token = claims.sign_with(JwtClaims::shared_key());
Source

async fn generate_token(body: Map) -> Result<(K, Map), Error>

Generates the access token and refresh token.

Source

async fn refresh_token(claims: &JwtClaims) -> Result<Map, Error>

Refreshes the access token.

Source

async fn verify_jwt_claims(claims: &JwtClaims) -> Result<bool, Error>

Verfifies the JWT claims.

Source

async fn verify_identity(user_id: K, body: &Map) -> Result<Map, Error>

Verifies the user identity.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§