Expand description
§r-token
A small, in-memory token authentication helper for actix-web.
The library exposes two main building blocks:
RTokenManager: issues and revokes tokens (UUID v4) and keeps an in-memory store.RUser: an actix-web extractor that validatesAuthorizationautomatically.
§How authentication works
- Your login handler calls
RTokenManager::loginwith a user id and a TTL (seconds). - The token is returned to the client (typically as plain text or JSON).
- The client sends the token back via
Authorizationheader:Authorization: <token>Authorization: Bearer <token>
- Any handler that declares an
RUserparameter becomes a protected endpoint. If extraction succeeds, the request is considered authenticated; otherwise actix-web returns an error.
§繁體中文
這是一個為 actix-web 設計的輕量級、純記憶體 token 驗證輔助庫。
主要由兩個元件構成:
RTokenManager: 產生/註銷 token(UUID v4),並在記憶體中維護映射表。RUser: actix-web 的 Extractor,會自動從Authorization讀取並驗證 token。
§驗證流程
- 登入端點呼叫
RTokenManager::login,傳入使用者 id 與 TTL(秒)。 - token 回傳給客戶端(常見為純文字或 JSON)。
- 客戶端透過
Authorizationheader 送回 token(支援Bearer前綴或不帶前綴)。 - 任何 handler 只要宣告
RUser參數即視為受保護端點;Extractor 成功才會進入 handler。
Structs§
- RToken
Manager - Issues, stores, and revokes authentication tokens.
- RUser
- An authenticated request context extracted from actix-web.
Enums§
- RToken
Error - Errors returned by r-token.