Class: AdsCommon::Auth::BaseHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/ads_common/auth/base_handler.rb

Direct Known Subclasses

OAuth2Handler, OAuth2ServiceAccountHandler

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ BaseHandler

Default initializer.



27
28
29
30
# File 'lib/ads_common/auth/base_handler.rb', line 27

def initialize(config)
  @config = config
  @token = nil
end

Instance Method Details

#auth_string(credentials) ⇒ Object

Returns authorization string. Needs to be overridden.

Raises:

  • (NotImplementedError)


53
54
55
# File 'lib/ads_common/auth/base_handler.rb', line 53

def auth_string(credentials)
  raise NotImplementedError, 'auth_string not overridden.'
end

#get_token(credentials = nil) ⇒ Object

Returns authorization token of some kind. Attempts to create a new one if the token has not yet been created and credentials present.



47
48
49
50
# File 'lib/ads_common/auth/base_handler.rb', line 47

def get_token(credentials = nil)
  @token = create_token(credentials) if @token.nil? and credentials
  return @token
end

#handle_error(error) ⇒ Object

This method handles an error according to the specifics of an authentication mechanism (to regenerate tokens, for example). The generic method simply re-raises the error.



41
42
43
# File 'lib/ads_common/auth/base_handler.rb', line 41

def handle_error(error)
  raise error
end

#property_changed(credential, value) ⇒ Object

Callback to be used by CredentialHandlers to notify the auth handler of a change in one of the credentials. Useful for e.g. invalidating a token. The generic method does nothing.



35
36
# File 'lib/ads_common/auth/base_handler.rb', line 35

def property_changed(credential, value)
end