Class: OAuth2::Strategy::AuthCode

Inherits:
Base
  • Object
show all
Defined in:
lib/oauth2/strategy/auth_code.rb

Overview

The Authorization Code Strategy

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from OAuth2::Strategy::Base

Instance Method Details

#authorize_params(params = {}) ⇒ Object

The required query parameters for the authorize URL

Parameters:

  • params (Hash) (defaults to: {})

    additional query parameters



12
13
14
# File 'lib/oauth2/strategy/auth_code.rb', line 12

def authorize_params(params = {})
  params.merge('response_type' => 'code', 'client_id' => @client.id)
end

#authorize_url(params = {}) ⇒ Object

The authorization URL endpoint of the provider

Parameters:

  • params (Hash) (defaults to: {})

    additional query parameters for the URL



19
20
21
22
# File 'lib/oauth2/strategy/auth_code.rb', line 19

def authorize_url(params = {})
  assert_valid_params(params)
  @client.authorize_url(authorize_params.merge(params))
end

#get_token(code, params = {}, opts = {}) ⇒ Object

Note:

that you must also provide a :redirect_uri with most OAuth 2.0 providers

Retrieve an access token given the specified validation code.

Parameters:

  • code (String)

    The Authorization Code value

  • params (Hash) (defaults to: {})

    additional params

  • opts (Hash) (defaults to: {})

    access_token_opts, @see Client#get_token



30
31
32
33
34
35
36
37
38
# File 'lib/oauth2/strategy/auth_code.rb', line 30

def get_token(code, params = {}, opts = {})
  params = {'grant_type' => 'authorization_code', 'code' => code}.merge(@client.redirection_params).merge(params)
  params_dup = params.dup
  params.each_key do |key|
    params_dup[key.to_s] = params_dup.delete(key) if key.is_a?(Symbol)
  end

  @client.get_token(params_dup, opts)
end