RTokenManager

Struct RTokenManager 

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

Issues, stores, and revokes authentication tokens.

This type is designed to be stored in actix-web application state (e.g. web::Data<RTokenManager>). Internally it uses an Arc<Mutex<...>>, so Clone creates another handle to the same shared store.

Tokens are generated as UUID v4 strings. Each token is associated with:

  • a user id (String)
  • an expiration timestamp (Unix epoch milliseconds)

§繁體中文

負責簽發、儲存與註銷 token 的管理器。

一般會放在 actix-web 的 application state 中(例如 web::Data<RTokenManager>)。 內部以 Arc<Mutex<...>> 共享狀態,因此 Clone 只是在同一份映射表上增加一個引用。

token 以 UUID v4 字串產生,並會綁定:

  • 使用者 id(String
  • 到期時間(Unix epoch 毫秒)

Implementations§

Source§

impl RTokenManager

Source

pub fn new() -> Self

Creates an empty manager.

§繁體中文

建立一個空的管理器。

Source

pub fn login(&self, id: &str, expire_time: u64) -> Result<String, RTokenError>

Issues a new token for the given user id.

expire_time is treated as TTL in seconds. The token will be considered invalid once the stored expiration timestamp is earlier than the current time.

Returns RTokenError::MutexPoisoned if the internal mutex is poisoned.

§繁體中文

為指定使用者 id 簽發新 token。

expire_time 會被視為 TTL(秒)。當儲存的到期時間早於目前時間時,token 會被視為無效。

若內部 mutex 發生 poisoned,會回傳 RTokenError::MutexPoisoned

Source

pub fn logout(&self, token: &str) -> Result<(), RTokenError>

Revokes a token by removing it from the in-memory store.

This operation is idempotent: removing a non-existing token is treated as success. Returns RTokenError::MutexPoisoned if the internal mutex is poisoned.

§繁體中文

從記憶體儲存表中移除 token,以達到註銷效果。

此操作具冪等性:移除不存在的 token 也視為成功。 若內部 mutex 發生 poisoned,會回傳 RTokenError::MutexPoisoned

Trait Implementations§

Source§

impl Clone for RTokenManager

Source§

fn clone(&self) -> RTokenManager

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for RTokenManager

Source§

fn default() -> RTokenManager

Returns the “default value” for a type. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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