Class: OAuth2::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/oauth2_patch/client.rb

Overview

The OAuth2::Client class

Instance Method Summary collapse

Instance Method Details

#get_token(params, access_token_opts = {}) ⇒ Object

Initializes an AccessToken by making a request to the token endpoint

Raises:

  • (Error)


7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/oauth2_patch/client.rb', line 7

def get_token(params, access_token_opts={})
  opts = {:raise_errors => true, :parse => params.delete(:parse)}
  if options[:token_method] == :post
    opts[:body] = params
    opts[:headers] =  {'Content-Type' => 'application/x-www-form-urlencoded'}
  else
    opts[:params] = params
  end
  response = request(options[:token_method], token_url, opts)
  raise Error.new(response) unless response.parsed.is_a?(Hash) && (response.parsed['access_token'] || response.parsed['accessToken'])
  AccessToken.from_hash(self, response.parsed.merge(access_token_opts))
end