Sigra.Plug.FetchBearer (Sigra v0.2.5)

Copy Markdown View Source

Extracts a bearer token from the Authorization header and assigns current_scope.

Auto-detects token type by format:

  • Tokens starting with the configured API token prefix -> opaque API token (DB lookup)
  • Tokens starting with "eyJ" and JWT enabled -> JWT (signature verification)
  • All other tokens -> opaque API token path (DB lookup)

Assigns current_scope with token_scopes, auth_method, and token_id fields. Skips if current_scope is already assigned.

Options

  • :config - A %Sigra.Config{} struct (required)
  • :scope_module - The module to call .new/1 on (the host app's Scope module)

Example

plug Sigra.Plug.FetchBearer,
  config: @sigra_config,
  scope_module: MyApp.Auth.Scope

Summary

Functions

Extract bearer token from Authorization header and assign current_scope.

Initialize the plug with the given options.

Functions

call(conn, opts)

(since 0.7.0)

Extract bearer token from Authorization header and assign current_scope.

Skips processing if current_scope is already assigned (D-53).

init(opts)

(since 0.7.0)

Initialize the plug with the given options.