ReckonJwt.Middleware (reckon_jwt v0.2.1)

View Source

JWT authentication middleware for Phoenix/Plug applications.

Provides authentication middleware that validates JWT tokens and sets authentication context in the connection.

Usage

# In your Phoenix router
pipeline :authenticated do
  plug ReckonJwt.Middleware, required_scopes: ["read", "write"]
end

# Optional authentication
plug ReckonJwt.Middleware, optional: true

Summary

Functions

Callback implementation for Plug.call/2.

Get the current account ID from the connection.

Check if the current user has the required scope.

Callback implementation for Plug.init/1.

Get JWT claims from the connection.

Require specific scopes for a controller action.

Functions

call(conn, opts)

Callback implementation for Plug.call/2.

current_account_id(conn, key \\ :current_account_id)

Get the current account ID from the connection.

has_scope?(conn, required_scope, claims_key \\ :jwt_claims)

Check if the current user has the required scope.

init(opts)

Callback implementation for Plug.init/1.

jwt_claims(conn, key \\ :jwt_claims)

Get JWT claims from the connection.

require_scopes(conn, required_scopes, claims_key \\ :jwt_claims)

Require specific scopes for a controller action.

Returns {:ok, conn} if the user has required scopes, or {:error, conn} with a 403 response if not.