Class: LpTokenAuth::Config
- Inherits:
-
Object
- Object
- LpTokenAuth::Config
- Defined in:
- lib/lp_token_auth/config.rb
Overview
LpTokenAuth::Config manages the configuration options for the token.
These can be set with the initializer provided with the generator.
Constant Summary collapse
- DEFAULT_VALUES =
Provides default values to token options ENV defaults defined as procs to ensure they return their latest value at call time (else they return nil, since ENV values may not be initialized before gem code)
{ algorithm: 'HS512', expires: (7 * 24), token_transport: [:cookie], jwe_private_key: -> { ENV['JWE_PRIVATE_KEY'] }, jwe_encryption: -> { ENV['JWE_ENCRYPTION'] || 'A256GCM' } }
Instance Attribute Summary collapse
-
#algorithm ⇒ Object
Creates virtual attributes for configuration options: *
algorithmis a string corresponding to token encryption algorithm to use *expiresis an integer corresponding to the number of hours that the token is active *secretis a string corresponding to the secret key used when encrypting the token *token_transportis a string indicating where to include the token in the HTTP response. -
#expires ⇒ Object
Creates virtual attributes for configuration options: *
algorithmis a string corresponding to token encryption algorithm to use *expiresis an integer corresponding to the number of hours that the token is active *secretis a string corresponding to the secret key used when encrypting the token *token_transportis a string indicating where to include the token in the HTTP response. -
#jwe_encryption ⇒ Object
Creates virtual attributes for configuration options: *
algorithmis a string corresponding to token encryption algorithm to use *expiresis an integer corresponding to the number of hours that the token is active *secretis a string corresponding to the secret key used when encrypting the token *token_transportis a string indicating where to include the token in the HTTP response. -
#jwe_private_key ⇒ Object
Creates virtual attributes for configuration options: *
algorithmis a string corresponding to token encryption algorithm to use *expiresis an integer corresponding to the number of hours that the token is active *secretis a string corresponding to the secret key used when encrypting the token *token_transportis a string indicating where to include the token in the HTTP response. -
#secret ⇒ Object
Creates virtual attributes for configuration options: *
algorithmis a string corresponding to token encryption algorithm to use *expiresis an integer corresponding to the number of hours that the token is active *secretis a string corresponding to the secret key used when encrypting the token *token_transportis a string indicating where to include the token in the HTTP response. -
#token_transport ⇒ Object
Creates virtual attributes for configuration options: *
algorithmis a string corresponding to token encryption algorithm to use *expiresis an integer corresponding to the number of hours that the token is active *secretis a string corresponding to the secret key used when encrypting the token *token_transportis a string indicating where to include the token in the HTTP response.
Instance Method Summary collapse
-
#get_default_value(key) ⇒ String, Integer
Retrieves default value for a token option.
-
#get_option(key) ⇒ String, Integer
Retrieves value for token option, either as set by the application, or the default.
Instance Attribute Details
#algorithm ⇒ Object
Creates virtual attributes for configuration options:
algorithmis a string corresponding to token encryption algorithm to useexpiresis an integer corresponding to the number of hours that the token is activesecretis a string corresponding to the secret key used when encrypting the tokentoken_transportis a string indicating where to include the token in the HTTP response
12 13 14 |
# File 'lib/lp_token_auth/config.rb', line 12 def algorithm @algorithm end |
#expires ⇒ Object
Creates virtual attributes for configuration options:
algorithmis a string corresponding to token encryption algorithm to useexpiresis an integer corresponding to the number of hours that the token is activesecretis a string corresponding to the secret key used when encrypting the tokentoken_transportis a string indicating where to include the token in the HTTP response
12 13 14 |
# File 'lib/lp_token_auth/config.rb', line 12 def expires @expires end |
#jwe_encryption ⇒ Object
Creates virtual attributes for configuration options:
algorithmis a string corresponding to token encryption algorithm to useexpiresis an integer corresponding to the number of hours that the token is activesecretis a string corresponding to the secret key used when encrypting the tokentoken_transportis a string indicating where to include the token in the HTTP response
12 13 14 |
# File 'lib/lp_token_auth/config.rb', line 12 def jwe_encryption @jwe_encryption end |
#jwe_private_key ⇒ Object
Creates virtual attributes for configuration options:
algorithmis a string corresponding to token encryption algorithm to useexpiresis an integer corresponding to the number of hours that the token is activesecretis a string corresponding to the secret key used when encrypting the tokentoken_transportis a string indicating where to include the token in the HTTP response
12 13 14 |
# File 'lib/lp_token_auth/config.rb', line 12 def jwe_private_key @jwe_private_key end |
#secret ⇒ Object
Creates virtual attributes for configuration options:
algorithmis a string corresponding to token encryption algorithm to useexpiresis an integer corresponding to the number of hours that the token is activesecretis a string corresponding to the secret key used when encrypting the tokentoken_transportis a string indicating where to include the token in the HTTP response
12 13 14 |
# File 'lib/lp_token_auth/config.rb', line 12 def secret @secret end |
#token_transport ⇒ Object
Creates virtual attributes for configuration options:
algorithmis a string corresponding to token encryption algorithm to useexpiresis an integer corresponding to the number of hours that the token is activesecretis a string corresponding to the secret key used when encrypting the tokentoken_transportis a string indicating where to include the token in the HTTP response
12 13 14 |
# File 'lib/lp_token_auth/config.rb', line 12 def token_transport @token_transport end |
Instance Method Details
#get_default_value(key) ⇒ String, Integer
Retrieves default value for a token option
39 40 41 42 |
# File 'lib/lp_token_auth/config.rb', line 39 def get_default_value(key) default = DEFAULT_VALUES[key] default.is_a?(Proc) ? default.call : default end |
#get_option(key) ⇒ String, Integer
Retrieves value for token option, either as set by the application, or the default
30 31 32 33 34 |
# File 'lib/lp_token_auth/config.rb', line 30 def get_option(key) option = send(key) || get_default_value(key) raise LpTokenAuth::Error, "Missing config option value: #{key}" unless option option end |