ReckonJwt (reckon_jwt v0.2.1)

View Source

JWT authentication library for Reckon microservices.

Provides a simple, consistent API for JWT token operations across all Reckon services including token generation, validation, and refresh functionality.

Configuration

config :reckon_jwt, ReckonJwt.Guardian,
  issuer: "reckon_identity",
  secret_key: "your-secret-key",
  ttl: {4, :hours}

Usage

# Generate session tokens
{:ok, tokens} = ReckonJwt.generate_session_tokens("account_123", "session_456")

# Validate tokens
{:ok, claims} = ReckonJwt.validate_token(token)

# Use in Phoenix pipelines
plug ReckonJwt.Middleware, required_scopes: ["read"]

Summary

Functions

Get configuration value with fallback.

Extract account ID from token (for debugging/logging).

Generate a simple access token without session context.

Generate session tokens (access + refresh) for authentication.

Refresh tokens using a valid refresh token.

Check if a token is expired.

Validate a session token specifically (requires session_id in claims).

Validate a JWT token and extract authentication information.

Functions

config(key, default \\ nil)

Get configuration value with fallback.

extract_account_id(token)

Extract account ID from token (for debugging/logging).

generate_access_token(account_id, custom_claims \\ %{})

Generate a simple access token without session context.

Useful for service-to-service authentication.

generate_session_tokens(account_id, session_id, device_info \\ %{})

Generate session tokens (access + refresh) for authentication.

Returns both access and refresh tokens with session information.

Examples

iex> {:ok, tokens} = ReckonJwt.generate_session_tokens("acc_123", "sess_456")
iex> tokens.account_id
"acc_123"
iex> tokens.session_id
"sess_456"

refresh_session_tokens(refresh_token)

Refresh tokens using a valid refresh token.

Generates new access token while maintaining session context.

token_expired?(token)

Check if a token is expired.

validate_session_token(token)

Validate a session token specifically (requires session_id in claims).

validate_token(token)

Validate a JWT token and extract authentication information.

Returns account and session information from the token.

Examples

iex> {:ok, tokens} = ReckonJwt.generate_session_tokens("acc_123", "sess_456")
iex> {:ok, result} = ReckonJwt.validate_token(tokens.access_token)
iex> result.account_id
"acc_123"