Class: OAuth2::Grant::AuthorizationCode

Inherits:
Base
  • Object
show all
Defined in:
lib/oauth2/grant/authorization_code.rb

Overview

Authorization Code Grant

Instance Attribute Summary

Attributes inherited from Base

#authorize_path, #client_id, #client_secret, #connection, #device_path, #host

Instance Method Summary collapse

Methods inherited from Base

#initialize, #make_request

Methods included from UrlHelper

#build_url, #generate_timestamp, #generate_urlsafe_key, http_basic_encode, #to_query

Constructor Details

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

Instance Method Details

#authorization_paramsObject

Default authorization request parameters



62
63
64
65
66
67
# File 'lib/oauth2/grant/authorization_code.rb', line 62

def authorization_params
  {
    :response_type => response_type,
    :client_id  => @client_id
  }
end

#authorization_path(params = {}) ⇒ Object

Authorization Request



17
18
19
20
# File 'lib/oauth2/grant/authorization_code.rb', line 17

def authorization_path(params={})
  params = params.merge(authorization_params)
  "#{@authorize_path}?#{to_query(params)}"
end

#authorization_url(params = {}) ⇒ Object



22
23
24
25
# File 'lib/oauth2/grant/authorization_code.rb', line 22

def authorization_url(params={})
  params = params.merge(authorization_params)
  build_url(host, :path => authorize_path, :params => params)
end

#fetch_authorization_url(opts = {}) ⇒ Object

Retrieve page at authorization path



39
40
41
42
43
# File 'lib/oauth2/grant/authorization_code.rb', line 39

def fetch_authorization_url(opts={})
  opts[:params] = opts.fetch(:params, {}).merge(authorization_params)
  method = opts.delete(:method) || :get
  make_request(method, @authorize_path, opts)
end

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

Retrieve an access token for a given auth code



50
51
52
53
54
55
56
57
58
59
# File 'lib/oauth2/grant/authorization_code.rb', line 50

def get_token(code, opts={})
  opts[:params] = {
    :grant_type => grant_type,
    :code       => code
  }.merge(opts.fetch(:params, {}))

  opts[:authenticate] ||= :headers
  method = opts.delete(:method) || :post
  make_request(method, token_path, opts)
end

#grant_typeObject



11
12
13
# File 'lib/oauth2/grant/authorization_code.rb', line 11

def grant_type
  "authorization_code"
end

#response_typeObject



7
8
9
# File 'lib/oauth2/grant/authorization_code.rb', line 7

def response_type
  "code"
end

#token_path(params = {}) ⇒ Object

Access Token Request



29
30
31
32
33
34
# File 'lib/oauth2/grant/authorization_code.rb', line 29

def token_path(params={})
  unless params.empty?
    return "#{@token_path}?#{to_query(params)}"
  end
  @token_path
end