Class: Philiprehberger::JwtKit::Configuration
- Inherits:
-
Object
- Object
- Philiprehberger::JwtKit::Configuration
- Defined in:
- lib/philiprehberger/jwt_kit/configuration.rb
Overview
Configuration singleton for JWT settings.
Instance Attribute Summary collapse
-
#algorithm ⇒ Symbol
Signing algorithm (:hs256, :hs384, :hs512).
-
#audience ⇒ String, ...
Expected audience for the ‘aud` claim.
-
#expiration ⇒ Integer
Default TTL in seconds for access tokens.
-
#issuer ⇒ String?
Optional issuer for the ‘iss` claim.
-
#refresh_expiration ⇒ Integer
Default TTL in seconds for refresh tokens.
-
#secret ⇒ String?
HMAC secret key (required for HS* algorithms).
-
#secrets ⇒ Array<Hash>?
Array of { kid: String, secret: String } for key rotation.
Instance Method Summary collapse
-
#algorithm_name ⇒ String
Returns the JWT algorithm header value.
-
#digest_algorithm ⇒ String
Returns the OpenSSL digest algorithm name.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
36 37 38 39 40 41 42 43 44 |
# File 'lib/philiprehberger/jwt_kit/configuration.rb', line 36 def initialize @secret = nil @algorithm = :hs256 @issuer = nil @audience = nil @expiration = 3600 @refresh_expiration = 86_400 * 7 @secrets = nil end |
Instance Attribute Details
#algorithm ⇒ Symbol
Returns signing algorithm (:hs256, :hs384, :hs512).
19 20 21 |
# File 'lib/philiprehberger/jwt_kit/configuration.rb', line 19 def algorithm @algorithm end |
#audience ⇒ String, ...
Returns expected audience for the ‘aud` claim.
25 26 27 |
# File 'lib/philiprehberger/jwt_kit/configuration.rb', line 25 def audience @audience end |
#expiration ⇒ Integer
Returns default TTL in seconds for access tokens.
28 29 30 |
# File 'lib/philiprehberger/jwt_kit/configuration.rb', line 28 def expiration @expiration end |
#issuer ⇒ String?
Returns optional issuer for the ‘iss` claim.
22 23 24 |
# File 'lib/philiprehberger/jwt_kit/configuration.rb', line 22 def issuer @issuer end |
#refresh_expiration ⇒ Integer
Returns default TTL in seconds for refresh tokens.
31 32 33 |
# File 'lib/philiprehberger/jwt_kit/configuration.rb', line 31 def refresh_expiration @refresh_expiration end |
#secret ⇒ String?
Returns HMAC secret key (required for HS* algorithms).
16 17 18 |
# File 'lib/philiprehberger/jwt_kit/configuration.rb', line 16 def secret @secret end |
#secrets ⇒ Array<Hash>?
Returns array of { kid: String, secret: String } for key rotation.
34 35 36 |
# File 'lib/philiprehberger/jwt_kit/configuration.rb', line 34 def secrets @secrets end |
Instance Method Details
#algorithm_name ⇒ String
Returns the JWT algorithm header value.
62 63 64 |
# File 'lib/philiprehberger/jwt_kit/configuration.rb', line 62 def algorithm_name @algorithm.to_s.upcase end |
#digest_algorithm ⇒ String
Returns the OpenSSL digest algorithm name.
50 51 52 53 54 55 56 57 |
# File 'lib/philiprehberger/jwt_kit/configuration.rb', line 50 def digest_algorithm case @algorithm when :hs256 then 'SHA256' when :hs384 then 'SHA384' when :hs512 then 'SHA512' else raise Error, "Unsupported algorithm: #{@algorithm}" end end |