Class: Authenticator
- Inherits:
-
Object
- Object
- Authenticator
- Includes:
- Singleton
- Defined in:
- lib/dvla/dataverse/support/authenticator.rb
Instance Method Summary collapse
- #authenticator_config ⇒ Object
-
#get_token ⇒ String
This function will setup the token using the client credentials only if the token is null or expired.
-
#setup_authentication_configs ⇒ Object
Setup the configuration for
AuthenticatorConfig
.
Instance Method Details
#authenticator_config ⇒ Object
57 58 59 |
# File 'lib/dvla/dataverse/support/authenticator.rb', line 57 def authenticator_config @authenticator_config ||= Struct::AuthenticatorConfig.new end |
#get_token ⇒ String
Note:
This function will setup the token using the client credentials only if the token is null or expired. Otherwise, the same token will be returned.
Be sure to call setup_authentication_configs
to setup the configuration before calling get_token
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dvla/dataverse/support/authenticator.rb', line 29 def get_token client = setup_client token = authenticator_config.latest_token time_now = Time.now.to_i if token.nil? || token.expires_at <= time_now client .client_credentials .get_token(params = { :scope => authenticator_config.scope }) .then { |token| authenticator_config.latest_token = token } end authenticator_config.latest_token.token end |
#setup_authentication_configs ⇒ Object
Note:
Setup the configuration for AuthenticatorConfig
. call this function before using get_token
.
This function is void
53 54 55 |
# File 'lib/dvla/dataverse/support/authenticator.rb', line 53 def setup_authentication_configs [config_auth_url, config_token_url, config_client_id, config_client_secret, config_scope].each(&:call) end |