Class: OmniAuth::Strategies::EdwithOauth2

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

Instance Method Summary collapse

Instance Method Details

#authorize_paramsObject



51
52
53
54
# File 'lib/omniauth/strategies/edwith_oauth2.rb', line 51

def authorize_params
  params = super
  Hash[params.map { |k, v| [k, v.respond_to?(:call) ? v.call(request) : v] }]
end

#build_access_tokenObject



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

def build_access_token
  verifier = request.params["code"]
  clientId = options.client_id
  clientSecret = options.client_secret
  token_url = options.client_options[:token_url]

  params = {:redirect_uri => callback_url}.merge(token_params.to_hash(:symbolize_keys => true))
  params = {'grant_type' => 'authorization_code', 'code' => verifier}.merge(client.redirection_params).merge(params)
  params = ::OAuth2::Authenticator.new(clientId, clientSecret, :request_body).apply(params)
   
  opts = {:raise_errors => options[:raise_errors], :parse => params.delete(:parse)}
  headers = params.delete(:headers) || {}

  opts[:body] = params
  opts[:headers] = {'Content-Type' => 'application/x-www-form-urlencoded'}
  opts[:headers].merge!(headers)
  
  response = client.request(:post, token_url, opts)

  if options[:raise_errors] && !(response.parsed.is_a?(Hash))
      error = Error.new(response)
      raise(error)
  end

  access_token_opts = deep_symbolize(options.auth_token_params)
  ::OAuth2::AccessToken.from_hash(client, response.parsed["data"].merge(access_token_opts))
end

#raw_infoObject



47
48
49
# File 'lib/omniauth/strategies/edwith_oauth2.rb', line 47

def raw_info
  @raw_info ||= access_token.post(options.client_options[:user_info_url]).parsed
end