Class: LpTokenAuth::Config

Inherits:
Object
  • Object
show all
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

{
  algorithm: 'HS512',
  expires: (7 * 24),
  token_transport: [:cookie],
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#algorithmObject

Creates virtual attributes for configuration options:

  • algorithm is a string corresponding to token encryption algorithm to use
  • expires is an integer corresponding to the number of hours that the token is active
  • secret is a string corresponding to the secret key used when encrypting the token
  • token_transport is 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

#expiresObject

Creates virtual attributes for configuration options:

  • algorithm is a string corresponding to token encryption algorithm to use
  • expires is an integer corresponding to the number of hours that the token is active
  • secret is a string corresponding to the secret key used when encrypting the token
  • token_transport is 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

#secretObject

Creates virtual attributes for configuration options:

  • algorithm is a string corresponding to token encryption algorithm to use
  • expires is an integer corresponding to the number of hours that the token is active
  • secret is a string corresponding to the secret key used when encrypting the token
  • token_transport is 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_transportObject

Creates virtual attributes for configuration options:

  • algorithm is a string corresponding to token encryption algorithm to use
  • expires is an integer corresponding to the number of hours that the token is active
  • secret is a string corresponding to the secret key used when encrypting the token
  • token_transport is 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_option(key) ⇒ String, Integer

Retrieves value for token option, either as set by the application, or the default

Parameters:

  • key (Symbol)

    the token option name

Returns:

  • (String, Integer)

    the value of the token option

Raises:

  • (LpTokenAuth::Error)

    if the option has not been set by the application and a default value does not exist


25
26
27
28
29
# File 'lib/lp_token_auth/config.rb', line 25

def get_option(key)
  option = send(key) || DEFAULT_VALUES[key]
  raise LpTokenAuth::Error "Missing config option value: #{ key }" unless option
  option
end