Class: OmniAuth::Shootproof::Client

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

Overview

rubocop:disable Metrics/ClassLength

Instance Method Summary collapse

Instance Method Details

#get_token(params, access_token_opts = {}, access_token_class = ::OAuth2::AccessToken) ⇒ AccessToken

Initializes an AccessToken by making a request to the token endpoint

Parameters:

  • params (Hash)

    a Hash of params for the token endpoint

  • access (Hash)

    token options, to pass to the AccessToken object

  • class (Class)

    of access token for easier subclassing OAuth2::AccessToken

Returns:

  • (AccessToken)

    the initalized AccessToken



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/omniauth/shootproof/client.rb', line 13

def get_token(params, access_token_opts = {}, access_token_class = ::OAuth2::AccessToken) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  params = ::OAuth2::Authenticator.new(id, secret, options[:auth_scheme]).apply(params)
  opts = {:raise_errors => options[:raise_errors], :parse => params.delete(:parse)}
  headers = params.delete(:headers) || {}
  if options[:token_method] == :post
    opts[:params] = params
    opts[:params].merge!(redirection_params)
    opts[:headers] = {'Content-Type' => 'application/x-www-form-urlencoded'}
  else
    error = Error.new('Must Be POST')
    raise(error)
  end
  opts[:headers].merge!(headers)
  response = request(options[:token_method], token_url, opts)
  if options[:raise_errors] && !(response.parsed.is_a?(Hash) && response.parsed['access_token'])
    error = Error.new(response)
    raise(error)
  end
  access_token_class.from_hash(self, response.parsed.merge(access_token_opts))
end

#redirection_paramsHash

The redirect_uri parameters, if configured

The redirect_uri query parameter is OPTIONAL (though encouraged) when requesting authorization. If it is provided at authorization time it MUST also be provided with the token exchange request.

Providing the :redirect_uri to the OAuth2::Client instantiation will take care of managing this.



50
51
52
53
54
55
56
# File 'lib/omniauth/shootproof/client.rb', line 50

def redirection_params
  if options[:redirect_uri]
    {:redirect_uri => options[:redirect_uri]}
  else
    {}
  end
end