Class: Usps::JwtAuth::Config
- Inherits:
-
Object
- Object
- Usps::JwtAuth::Config
- Defined in:
- lib/usps/jwt_auth/config.rb
Overview
Configure JWT Authentication
Constant Summary collapse
- REQUIRED_OPTIONS =
%i[audience is_admin find_member].freeze
Instance Attribute Summary collapse
-
#algorithm ⇒ Object
Returns the value of attribute algorithm.
-
#audience ⇒ Object
Returns the value of attribute audience.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#find_member ⇒ Object
Returns the value of attribute find_member.
-
#is_admin ⇒ Object
Returns the value of attribute is_admin.
-
#issuer_base ⇒ Object
Returns the value of attribute issuer_base.
-
#issuers ⇒ Object
Returns the value of attribute issuers.
-
#key_size ⇒ Object
Returns the value of attribute key_size.
-
#public_keys_url ⇒ Object
Returns the value of attribute public_keys_url.
-
#publisher ⇒ Object
Returns the value of attribute publisher.
Instance Method Summary collapse
-
#initialize {|_self| ... } ⇒ Config
constructor
A new instance of Config.
- #keys_path ⇒ Object
- #keys_path=(path) ⇒ Object
- #public_keys_path ⇒ Object
- #public_keys_path=(path) ⇒ Object
- #raw_keys_path ⇒ Object
- #raw_public_keys_path ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Config
Returns a new instance of Config.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/usps/jwt_auth/config.rb', line 14 def initialize @environment = defined?(Rails) ? Rails.env : ActiveSupport::StringInquirer.new('development') @keys_path = Pathname.new('config/keys') @public_keys_path = Pathname.new('config/public_keys') @key_size = ENV.fetch('JWT_KEY_SIZE', '4096').to_i @algorithm = ENV.fetch('JWT_ALGORITHM', 'RS512') @issuer_base = ENV.fetch('JWT_ISSUER_BASE', 'usps:1') @issuers = ENV.fetch('JWT_ISSUERS', []) @audience = ENV.fetch('JWT_AUDIENCE', nil) # Base URL of the shared public-key store (CloudFront). Consumers fetch # "<public_keys_url>/<fingerprint>.pub" on a local cache miss. nil disables fetching. # `publisher` (defaults to nil) is an optional callable invoked as # publisher.call(fingerprint, pem) when an issuer writes a new public key. @public_keys_url = ENV.fetch('JWT_PUBLIC_KEYS_URL', nil) yield self if block_given? # Also support setting options on initialize end |
Instance Attribute Details
#algorithm ⇒ Object
Returns the value of attribute algorithm.
10 11 12 |
# File 'lib/usps/jwt_auth/config.rb', line 10 def algorithm @algorithm end |
#audience ⇒ Object
Returns the value of attribute audience.
10 11 12 |
# File 'lib/usps/jwt_auth/config.rb', line 10 def audience @audience end |
#environment ⇒ Object
Returns the value of attribute environment.
12 13 14 |
# File 'lib/usps/jwt_auth/config.rb', line 12 def environment @environment end |
#find_member ⇒ Object
Returns the value of attribute find_member.
10 11 12 |
# File 'lib/usps/jwt_auth/config.rb', line 10 def find_member @find_member end |
#is_admin ⇒ Object
Returns the value of attribute is_admin.
10 11 12 |
# File 'lib/usps/jwt_auth/config.rb', line 10 def is_admin @is_admin end |
#issuer_base ⇒ Object
Returns the value of attribute issuer_base.
10 11 12 |
# File 'lib/usps/jwt_auth/config.rb', line 10 def issuer_base @issuer_base end |
#issuers ⇒ Object
Returns the value of attribute issuers.
10 11 12 |
# File 'lib/usps/jwt_auth/config.rb', line 10 def issuers @issuers end |
#key_size ⇒ Object
Returns the value of attribute key_size.
10 11 12 |
# File 'lib/usps/jwt_auth/config.rb', line 10 def key_size @key_size end |
#public_keys_url ⇒ Object
Returns the value of attribute public_keys_url.
10 11 12 |
# File 'lib/usps/jwt_auth/config.rb', line 10 def public_keys_url @public_keys_url end |
#publisher ⇒ Object
Returns the value of attribute publisher.
10 11 12 |
# File 'lib/usps/jwt_auth/config.rb', line 10 def publisher @publisher end |
Instance Method Details
#keys_path ⇒ Object
36 37 38 |
# File 'lib/usps/jwt_auth/config.rb', line 36 def keys_path defined?(Rails) ? Rails.root.join(@keys_path) : @keys_path end |
#keys_path=(path) ⇒ Object
44 45 46 |
# File 'lib/usps/jwt_auth/config.rb', line 44 def keys_path=(path) @keys_path = path.is_a?(Pathname) ? path : Pathname.new(path) end |
#public_keys_path ⇒ Object
48 49 50 |
# File 'lib/usps/jwt_auth/config.rb', line 48 def public_keys_path defined?(Rails) ? Rails.root.join(@public_keys_path) : @public_keys_path end |
#public_keys_path=(path) ⇒ Object
56 57 58 |
# File 'lib/usps/jwt_auth/config.rb', line 56 def public_keys_path=(path) @public_keys_path = path.is_a?(Pathname) ? path : Pathname.new(path) end |
#raw_keys_path ⇒ Object
40 41 42 |
# File 'lib/usps/jwt_auth/config.rb', line 40 def raw_keys_path @keys_path end |
#raw_public_keys_path ⇒ Object
52 53 54 |
# File 'lib/usps/jwt_auth/config.rb', line 52 def raw_public_keys_path @public_keys_path end |
#validate! ⇒ Object
60 61 62 63 64 65 |
# File 'lib/usps/jwt_auth/config.rb', line 60 def validate! = REQUIRED_OPTIONS.select { public_send(it).nil? } return unless .any? raise "Missing required options: #{.join(', ')}" end |