Skip to main content

OAuth2Manager

Struct OAuth2Manager 

Source
pub struct OAuth2Manager { /* private fields */ }
Expand description

OAuth2 protocol manager backed by SaTokenDao. 基于 SaTokenDao 的 OAuth2 协议管理器。

Implementations§

Source§

impl OAuth2Manager

Source

pub fn new(storage: Arc<dyn SaStorage>) -> Self

Build from raw storage with default config / key prefix. 从原始存储构建(默认配置与键前缀)。

Source

pub fn from_dao(dao: Arc<SaTokenDao>) -> Self

Build from an existing Dao (preferred when sharing Manager keys). 从已有 Dao 构建(与 Manager 共享键时推荐)。

Source

pub fn from_manager(manager: &SaTokenManager) -> Self

Align Dao / key prefix with an existing manager. 与已有 manager 对齐 Dao / 键前缀。

Source

pub fn with_ttl( self, code_ttl: i64, token_ttl: i64, refresh_token_ttl: i64, ) -> Self

Override code / access / refresh TTLs (seconds). 覆盖授权码 / 访问令牌 / 刷新令牌 TTL(秒)。

Source

pub fn with_require_pkce(self, require: bool) -> Self

Require PKCE for confidential clients as well. 机密客户端也强制要求 PKCE。

Source

pub fn with_allow_legacy_plain_secret(self, allow: bool) -> Self

Allow verifying legacy plaintext secrets stored under the hash field. 允许校验哈希字段中残留的历史明文密钥。

Source

pub fn with_password_verifier(self, verifier: Arc<dyn PasswordVerifier>) -> Self

Inject password grant verifier (required for password grant). 注入密码模式校验器(password grant 必需)。

Source

pub async fn register_client_with_secret( &self, client: OAuth2Client, plain_secret: &str, ) -> SaTokenResult<()>

Register a client after hashing plain_secret (unless public). 注册客户端:对 plain_secret 哈希后落库(公共客户端除外)。

Source

pub async fn register_client(&self, client: &OAuth2Client) -> SaTokenResult<()>

Compatibility wrapper: hashes client.client_secret when hash is empty. 兼容包装:hash 为空时哈希 client.client_secret。

Source

pub async fn get_client(&self, client_id: &str) -> SaTokenResult<OAuth2Client>

Load a registered client by id. 按 id 加载已注册客户端。

Source

pub async fn verify_client( &self, client_id: &str, client_secret: &str, ) -> SaTokenResult<bool>

Verify client credentials (public clients always succeed). 校验客户端凭据(公共客户端恒成功)。

Source

pub fn generate_authorization_code( &self, client_id: String, user_id: String, redirect_uri: String, scope: Vec<String>, pkce: Option<PkceChallenge>, state: Option<String>, ) -> AuthorizationCode

Build an authorization code (does not persist). 构造授权码(不落库)。

Source

pub async fn store_authorization_code( &self, auth_code: &AuthorizationCode, ) -> SaTokenResult<()>

Persist an authorization code with TTL. 以 TTL 持久化授权码。

Source

pub async fn consume_authorization_code( &self, code: &str, ) -> SaTokenResult<AuthorizationCode>

Atomically consume an authorization code (take_string). 原子消费授权码(take_string)。

Source

pub async fn exchange_code_for_token( &self, code: &str, client_id: &str, client_secret: &str, redirect_uri: &str, code_verifier: Option<&str>, ) -> SaTokenResult<AccessToken>

Exchange authorization code for tokens (with optional PKCE). 用授权码兑换令牌(可选 PKCE)。

Source

pub async fn generate_access_token( &self, client_id: &str, user_id: &str, scope: Vec<String>, ) -> SaTokenResult<AccessToken>

Issue and persist an access + refresh token pair. 签发并持久化访问令牌 + 刷新令牌对。

Source

pub async fn verify_access_token( &self, access_token: &str, ) -> SaTokenResult<OAuth2TokenInfo>

Load and validate an access token. 加载并校验访问令牌。

Source

pub async fn refresh_access_token( &self, refresh_token: &str, client_id: &str, client_secret: &str, ) -> SaTokenResult<AccessToken>

Rotate refresh token atomically (take_string + rewrite on failure). 原子轮换刷新令牌(take_string;失败时回写)。

Source

pub async fn revoke_token(&self, token: &str) -> SaTokenResult<()>

Revoke access and/or refresh token keys (errors propagate). 撤销访问/刷新令牌键(错误上抛)。

Source

pub fn validate_redirect_uri( &self, client: &OAuth2Client, redirect_uri: &str, ) -> bool

Exact-match redirect URI validation (rejects empty / fragment). 精确匹配重定向 URI(拒绝空串 / fragment)。

Source

pub fn validate_scope( &self, client: &OAuth2Client, requested_scope: &[String], ) -> bool

True when every requested scope is registered on the client. 请求的每个 scope 均已在客户端注册时返回 true。

Source

pub fn supports_grant_type(client: &OAuth2Client, grant_type: &str) -> bool

True when the client lists the grant type. 客户端声明了该授权类型时返回 true。

Source

pub async fn password_grant( &self, client_id: &str, client_secret: &str, username: &str, password: &str, scope: Vec<String>, ) -> SaTokenResult<AccessToken>

Resource-owner password grant (requires injected verifier). 资源所有者密码模式(需注入校验器)。

Source

pub async fn client_credentials_grant( &self, client_id: &str, client_secret: &str, scope: Vec<String>, ) -> SaTokenResult<AccessToken>

Client-credentials grant (confidential clients only). 客户端凭证模式(仅机密客户端)。

Source

pub async fn issue_token( &self, req: TokenIssueRequest, ) -> SaTokenResult<AccessToken>

Dispatch token issuance by grant type. 按授权类型分发令牌签发。

Source

pub async fn issue_authorization_code( &self, client_id: String, user_id: String, redirect_uri: String, scope: Vec<String>, pkce: Option<PkceChallenge>, state: Option<String>, ) -> SaTokenResult<AuthorizationCode>

Validate client + redirect + scope + PKCE, then generate and store a code. 校验客户端 / 重定向 / scope / PKCE 后生成并存储授权码。

Trait Implementations§

Source§

impl Debug for OAuth2Manager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ForyObject for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more