Class: Shutl::Auth::Authenticator
- Inherits:
-
Object
- Object
- Shutl::Auth::Authenticator
- Defined in:
- lib/shutl/auth/authenticator.rb
Instance Method Summary collapse
- #access_token ⇒ Object
- #authenticated_request(&blk) ⇒ Object
-
#initialize(options = {}) ⇒ Authenticator
constructor
A new instance of Authenticator.
- #request_access_token ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Authenticator
Returns a new instance of Authenticator.
6 7 8 9 10 11 12 |
# File 'lib/shutl/auth/authenticator.rb', line 6 def initialize( = {}) Shutl::Auth.logger.debug "building a new authenticator" self.cache_key = .fetch(:cache_key) { :access_token } self.client_id = .fetch(:client_id) self.client_secret = .fetch(:client_secret) self.url = .fetch(:url) end |
Instance Method Details
#access_token ⇒ Object
14 15 16 17 |
# File 'lib/shutl/auth/authenticator.rb', line 14 def access_token return read_token if read_token set_token request_access_token end |
#authenticated_request(&blk) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/shutl/auth/authenticator.rb', line 19 def authenticated_request &blk begin yield rescue Shutl::UnauthorizedAccess => e Shutl::Auth.logger.debug "Shutl::UnauthorizedAccess - resetting access token" set_token nil access_token yield end end |
#request_access_token ⇒ Object
30 31 32 33 34 35 |
# File 'lib/shutl/auth/authenticator.rb', line 30 def request_access_token return read_token if read_token Shutl::Auth.logger.debug "request_access_token: cached? #{!!read_token}" AccessTokenRequest.new(opts).access_token end |