USPS JWT Authentication

Gem Version

Installation

Add the gem to your Gemfile:

gem 'usps-jwt_auth'

Then run the install task:

bundle exec rails usps:jwt:install

Configuration

Config options audience, is_admin, and find_member are required.

Usps::JwtAuth.configure do |config|
  # This will default to `Rails.env` if available.
  config.environment = 'development'

  # These will append to `Rails.root` if available.
  config.keys_path        = 'config/keys'
  config.public_keys_path = 'config/public_keys'

  # These options will default to the listed `ENV` variable if available.
  #
  # The ultimate defaults are listed to the right.
  #
  config.audience    = 'example'   # ENV['JWT_AUDIENCE']    # nil
  config.algorithm   = 'RS512'     # ENV['JWT_ALGORITHM']   # 'RS512'
  config.key_size    = 4096        # ENV['JWT_KEY_SIZE']    # 4096
  config.issuer_base = 'usps:1'    # ENV['JWT_ISSUER_BASE'] # 'usps:1'
  config.issuers     = ['admin:1'] # ENV['JWT_ISSUERS']     # []

  config.is_admin = ->(user) { Pundit.policy(user, :admin).admin? }
  config.find_member = ->(certificate) { Members::Member.find(certificate) }
end

Usage

class ApplicationController < ActionController::Base
  include Usps::JwtAuth::Concern

  before_action :authenticate_user_from_jwt!
  # skip_before_action :authenticate_user_from_jwt!, only: %i[]

  # ...
end