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§
Sourceconst ACCOUNT_FIELD: &'static str = "account"
const ACCOUNT_FIELD: &'static str = "account"
Account field name.
Sourceconst PASSWORD_FIELD: &'static str = "password"
const PASSWORD_FIELD: &'static str = "password"
Password field name.
Sourceconst ROLE_FIELD: Option<&'static str> = _
const ROLE_FIELD: Option<&'static str> = _
Role field name.
Sourceconst TENANT_ID_FIELD: Option<&'static str> = None
const TENANT_ID_FIELD: Option<&'static str> = None
Tenant-ID field name.
Sourceconst LOGIN_AT_FIELD: Option<&'static str> = None
const LOGIN_AT_FIELD: Option<&'static str> = None
Login-at field name.
Sourceconst LOGIN_IP_FIELD: Option<&'static str> = None
const LOGIN_IP_FIELD: Option<&'static str> = None
Login-IP field name.
Provided Methods§
Sourcefn into_standard_claims(self) -> Map
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());
Sourceasync fn generate_token(body: Map) -> Result<(K, Map), Error>
async fn generate_token(body: Map) -> Result<(K, Map), Error>
Generates the access token and refresh token.
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.