Class: Tikkie::Api::Authentication
- Inherits:
-
Object
- Object
- Tikkie::Api::Authentication
- Defined in:
- lib/tikkie/api/authentication.rb
Overview
Provides authentication for the ABN AMRO OAuth API. see developer.abnamro.com/get-started#authentication
Instance Method Summary collapse
- #authenticate ⇒ Object
-
#initialize(config) ⇒ Authentication
constructor
A new instance of Authentication.
Constructor Details
#initialize(config) ⇒ Authentication
Returns a new instance of Authentication.
13 14 15 |
# File 'lib/tikkie/api/authentication.rb', line 13 def initialize(config) @config = config end |
Instance Method Details
#authenticate ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tikkie/api/authentication.rb', line 17 def authenticate uri = URI.parse(File.join(@config.api_url, "/oauth/token")) request = Net::HTTP::Post.new(uri) request["Api-Key"] = @config.api_key request.set_form_data( client_assertion: jwt_token, client_assertion_type: "urn:ietf:params:oauth:client-assertion-type:jwt-bearer", grant_type: "client_credentials", scope: "tikkie" ) response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http| http.request(request) end if response.is_a?(Net::HTTPSuccess) json = JSON.parse(response.body, symbolize_names: true) Tikkie::Api::AccessToken.new(json[:access_token], json[:expires_in]) else raise Tikkie::Api::AuthenticationException, response end end |