Crate r_token

Crate r_token 

Source
Expand description

§r-token

§日本語

actix-web / axum 向けの軽量なインメモリ token 認証ヘルパーです。

このライブラリは主に次の 2 つを提供します:

  • RTokenManager: token(UUID v4)の発行/失効と、インメモリストアの管理
  • RUser: Authorization を自動検証する extractor(actix-web / axum)

§認証の流れ

  1. ログイン処理で RTokenManager::login を呼び、ユーザー ID と TTL(秒)を渡します。
  2. token をクライアントへ返します(多くはプレーンテキストまたは JSON)。
  3. クライアントは Authorization header で token を送ります:
    • Authorization: <token>
    • Authorization: Bearer <token>
  4. handler が RUser を引数に持つと保護されたエンドポイントになります。抽出が成功すれば認証済みとして扱われ、失敗すれば actix-web がエラーを返します。

§English

A small, in-memory token authentication helper for actix-web and axum.

The library exposes two main building blocks:

  • RTokenManager: issues and revokes tokens (UUID v4) and keeps an in-memory store.
  • RUser: an extractor that validates Authorization automatically (actix-web / axum).

§How authentication works

  1. Your login handler calls RTokenManager::login with a user id and a TTL (seconds).
  2. The token is returned to the client (typically as plain text or JSON).
  3. The client sends the token back via Authorization header:
    • Authorization: <token>
    • Authorization: Bearer <token>
  4. Any handler that declares an RUser parameter becomes a protected endpoint. If extraction succeeds, the request is considered authenticated; otherwise the framework returns an error.

Structs§

RTokenManager
日本語
RUser
日本語
TokenSourceConfig
日本語

Enums§

RTokenError
日本語
TokenSourcePriority
日本語

Constants§

TOKEN_COOKIE_NAME
日本語

Functions§

extract_token_from_request
日本語
extract_token_from_request_with_config
日本語