Class: OAuth2::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/omniauth/strategies/varejonline.rb

Instance Method Summary collapse

Instance Method Details

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

Raises:

  • (Error)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/omniauth/strategies/varejonline.rb', line 54

def get_token(params, access_token_opts={})
  opts = {:raise_errors => options[:raise_errors], :parse => params.delete(:parse)}
  
  if options[:token_method] == :post
    headers = params.delete(:headers)

    if params[:formato] == :json
      params[:redirect_uri] = params[:redirect_uri].gsub(/\?(.*)/, "")

      opts[:body] = params.to_json
      opts[:headers] =  {'Content-Type' => 'application/json'}
    else
      opts[:body] = params
      opts[:headers] =  {'Content-Type' => 'application/x-www-form-urlencoded'}
    end

    opts[:headers].merge!(headers) if headers
  else
    opts[:params] = params
  end

  response = request(options[:token_method], token_url, opts)
  raise Error.new(response) if options[:raise_errors] && !(response.parsed.is_a?(Hash) && response.parsed['access_token'])
  AccessToken.from_hash(self, response.parsed.merge(access_token_opts))
end