Class: ResoTransport::Authentication::FetchTokenAuth
- Inherits:
-
AuthStrategy
- Object
- AuthStrategy
- ResoTransport::Authentication::FetchTokenAuth
- Defined in:
- lib/reso_transport/authentication/fetch_token_auth.rb
Instance Attribute Summary collapse
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#grant_type ⇒ Object
readonly
Returns the value of attribute grant_type.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Attributes inherited from AuthStrategy
Instance Method Summary collapse
- #authenticate ⇒ Object
-
#initialize(options) ⇒ FetchTokenAuth
constructor
A new instance of FetchTokenAuth.
Methods inherited from AuthStrategy
Constructor Details
#initialize(options) ⇒ FetchTokenAuth
Returns a new instance of FetchTokenAuth.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/reso_transport/authentication/fetch_token_auth.rb', line 6 def initialize() @grant_type = .fetch(:grant_type, "client_credentials") @scope = .fetch(:scope, "api") @client_id = .fetch(:client_id) @client_secret = .fetch(:client_secret) @endpoint = .fetch(:endpoint) @connection = Faraday.new(@endpoint) do |faraday| faraday.request :url_encoded faraday.response :logger, ResoTransport.configuration.logger if ResoTransport.configuration.logger faraday.adapter Faraday.default_adapter faraday.basic_auth @client_id, @client_secret end end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
4 5 6 |
# File 'lib/reso_transport/authentication/fetch_token_auth.rb', line 4 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
4 5 6 |
# File 'lib/reso_transport/authentication/fetch_token_auth.rb', line 4 def client_secret @client_secret end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
4 5 6 |
# File 'lib/reso_transport/authentication/fetch_token_auth.rb', line 4 def connection @connection end |
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
4 5 6 |
# File 'lib/reso_transport/authentication/fetch_token_auth.rb', line 4 def endpoint @endpoint end |
#grant_type ⇒ Object (readonly)
Returns the value of attribute grant_type.
4 5 6 |
# File 'lib/reso_transport/authentication/fetch_token_auth.rb', line 4 def grant_type @grant_type end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
4 5 6 |
# File 'lib/reso_transport/authentication/fetch_token_auth.rb', line 4 def scope @scope end |
Instance Method Details
#authenticate ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/reso_transport/authentication/fetch_token_auth.rb', line 21 def authenticate response = connection.post nil, auth_params json = JSON.parse response.body unless response.success? = "#{response.reason_phrase}: #{json['error'] || response.body}" raise ResoTransport::AccessDenied, response: response, message: end Access.new({ access_token: json.fetch('access_token'), expires_in: json.fetch('expires_in', 1 << (1.size * 8 - 2) - 1), token_type: json.fetch('token_type', "Bearer") }) end |