Class: OmniAuth::Strategies::Qiita::Client

Inherits:
OAuth2::Client
  • Object
show all
Defined in:
lib/omniauth/strategies/qiita/client.rb

Instance Method Summary collapse

Instance Method Details

#get_token_with_json(params, access_token_opts = {}, access_token_class = AccessToken) ⇒ Object Also known as: get_token



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/omniauth/strategies/qiita/client.rb', line 5

def get_token_with_json(params, access_token_opts = {}, access_token_class = AccessToken)
  opts = {:raise_errors => options[:raise_errors], :parse => params.delete(:parse)}
  if options[:token_method] == :post
    headers = params.delete(:headers)
    opts[:body] = params.to_json
    opts[:headers] =  {'Content-Type' => 'application/json'}
    opts[:headers].merge!(headers) if headers
  else
    opts[:params] = params
  end
  response = request(options[:token_method], token_url, opts)
  error = Error.new(response)
  fail(error) if options[:raise_errors] && !(response.parsed.is_a?(Hash) && response.parsed['token'])
  access_token_class.from_hash(self, response.parsed.merge(access_token_opts))
end