Skip to main content

RefreshAction

Struct RefreshAction 

Source
pub struct RefreshAction<R: RefreshClaimsResolver = DefaultRefreshClaims, A: AuthAuditHook = TracingAuditHook> { /* private fields */ }
Expand description

刷新 Action:用 Refresh Token 换取新的 Access Token。公开。

仅调用一次 TokenManager::verify_token_checked 完成验证(签名 + 过期 + 黑名单),随后将已验证的 TokenClaims 直接传给 TokenManager::rotate_refresh_token_from_claims,跳过内部二次验证, 节省 2 次 Redis RTT。自定义声明由注入的 RefreshClaimsResolver 决定, 默认 DefaultRefreshClaims 不附加声明,零配置即可使用。

§示例

ⓘ
use yang_base::action::auth::{RefreshAction, RefreshClaimsResolver};
use yang_base::action::ActionContext;
use yang_base::error::BaseError;
use async_trait::async_trait;

// 零配置:默认 resolver
let refresh = RefreshAction::default();

// 自定义:刷新时回查用户最新角色
struct RoleResolver;
#[async_trait]
impl RefreshClaimsResolver for RoleResolver {
    async fn resolve(&self, _ctx: &ActionContext, sub: &str)
        -> Result<serde_json::Value, BaseError>
    {
        Ok(serde_json::json!({ "role": "user", "sub": sub }))
    }
}
let refresh = RefreshAction::new(RoleResolver);

Implementations§

Source§

impl<R: RefreshClaimsResolver> RefreshAction<R, TracingAuditHook>

Source

pub fn new(resolver: R) -> Self

用业务声明解析器创建 RefreshAction(默认 tracing 审计钩子)。

Source§

impl<R: RefreshClaimsResolver, A: AuthAuditHook> RefreshAction<R, A>

Source

pub fn with_audit(resolver: R, audit: A) -> Self

用业务声明解析器 + 自定义审计钩子创建 RefreshAction。

Trait Implementations§

Source§

impl<R: Default + RefreshClaimsResolver, A: Default + AuthAuditHook> Default for RefreshAction<R, A>

Source§

fn default() -> RefreshAction<R, A>

Returns the “default value” for a type. Read more
Source§

impl<R: RefreshClaimsResolver, A: AuthAuditHook> TypedAction for RefreshAction<R, A>

Source§

fn name(&self) -> &'static str

Action 唯一标识
Source§

fn display_name(&self) -> &'static str

用户可见的显示名(默认返回 name)
Source§

fn description(&self) -> &'static str

简介(默认返回空字符串)
Source§

fn http_method(&self) -> HttpMethod

原子注册的 HTTP method;默认 POST。
Source§

fn path(&self) -> &'static str

原子注册的 HTTP path;未显式配置时由 Action 名生成 /<name>。
Source§

fn success_status(&self) -> u16

成功响应状态码。
Source§

fn response_kind(&self) -> ActionResponseKind

成功响应的静态类别;默认是普通 JSON。
Source§

fn is_public(&self) -> bool

是否公开(默认 false)
Source§

fn permission_mode(&self) -> PermissionMode

权限匹配模式(默认 All,即 AND 语义)
Source§

fn permissions(&self) -> &'static [Permission]

所需权限列表(默认为空)
Source§

fn input_schema(&self) -> &'static RootSchema

入参 JSON Schema(OnceLock 生成)
Source§

fn output_schema(&self) -> &'static RootSchema

出参 JSON Schema
Source§

fn meta_static(&self) -> &'static ActionMeta

静态元信息聚合体
Source§

fn multipart_spec(&self) -> Option<MultipartSpec>

可选的受限 multipart 请求契约;默认只接受 JSON。
Source§

impl<R: RefreshClaimsResolver, A: AuthAuditHook> TypedHandler for RefreshAction<R, A>

Refresh Token 旋转刷新 Action。

此方法使用 Token Rotation 模式:每次刷新时同时撤销旧 Refresh Token 并签发 新的 Token 对(Access Token + Refresh Token),防止 Refresh Token 被盗后的 无限刷新攻击。

§破坏性变更(BREAKING CHANGE)

原 RefreshAction 仅返回 AccessTokenResponse(只含新的 Access Token)。 现改为返回 TokenPairResponse(同时包含新的 Access Token 与新的 Refresh Token)。 请更新客户端以替换保存的 Refresh Token,否则旧 Refresh Token 将无法用于后续刷新。

Source§

type Input = RefreshInput

输入类型(请求体反序列化目标)
Source§

type Output = TokenPairResponse

输出类型(响应数据序列化源)
Source§

fn handle<'life0, 'async_trait>( &'life0 self, ctx: ActionContext, input: RefreshInput, ) -> Pin<Box<dyn Future<Output = Result<TokenPairResponse, BaseError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

业务执行
Source§

fn decode_input( &self, ctx: &mut ActionContext, ) -> Result<Self::Input, BaseError>

从请求构造 Input。旧 TypedHandler 默认读取 body;原生 Action 由 ParamInput 按 body/query/path/header 的静态定义覆盖该行为。
Source§

fn bind_registry(&self, _registry: &Registry) -> Result<(), BaseError>

AppBuilder 构建期依赖绑定钩子。
Source§

fn handle_future( &self, ctx: ActionContext, input: Self::Input, ) -> Pin<Box<dyn Future<Output = Result<Self::Output, BaseError>> + Send + '_>>

返回 Handler future;原生 Action 覆盖此入口以避免 async-trait 适配层二次装箱。

Auto Trait Implementations§

§

impl<R, A> Freeze for RefreshAction<R, A>
where R: Freeze, A: Freeze,

§

impl<R, A> RefUnwindSafe for RefreshAction<R, A>

§

impl<R, A> Send for RefreshAction<R, A>

§

impl<R, A> Sync for RefreshAction<R, A>

§

impl<R, A> Unpin for RefreshAction<R, A>
where R: Unpin, A: Unpin,

§

impl<R, A> UnsafeUnpin for RefreshAction<R, A>
where R: UnsafeUnpin, A: UnsafeUnpin,

§

impl<R, A> UnwindSafe for RefreshAction<R, A>
where R: UnwindSafe, A: UnwindSafe,

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> DynAction for T
where T: TypedAction,

Source§

fn dispatch<'life0, 'async_trait>( &'life0 self, ctx: ActionContext, ) -> Pin<Box<dyn Future<Output = Result<ApiResponse, BaseError>> + Send + 'async_trait>>
where 'life0: 'async_trait, T: 'async_trait,

派发:从 ctx 中提取输入、执行业务逻辑、封装响应
Source§

fn meta(&self) -> &'static ActionMeta

获取静态元信息
Source§

fn input_type_id(&self) -> TypeId

返回强类型输入的 TypeId;手写擦除实现默认不支持内部强类型调用。
Source§

fn output_type_id(&self) -> TypeId

返回强类型输出的 TypeId;手写擦除实现默认不支持内部强类型调用。
Source§

fn call_boxed<'life0, 'async_trait>( &'life0 self, ctx: ActionContext, input: Box<dyn Any + Send>, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Any + Send>, BaseError>> + Send + 'async_trait>>
where 'life0: 'async_trait, T: 'async_trait,

使用已经反序列化的输入直接调用 Handler,不经过 JSON。
Source§

fn bind_registry(&self, registry: &Registry) -> Result<(), BaseError>

Registry 冻结后的构建期绑定钩子。
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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