class OAuth2Client::Grant::AuthorizationCode

Authorization Code Grant @see tools.ietf.org/html/draft-ietf-oauth-v2-31#section-4.1

Public Instance Methods

authorization_params() click to toggle source

Default authorization request parameters

# File lib/oauth2-client/grant/authorization_code.rb, line 62
def authorization_params
  {
    :response_type => response_type,
    :client_id  => @client_id
  }
end
authorization_path(params={}) click to toggle source

Authorization Request @see tools.ietf.org/html/draft-ietf-oauth-v2-31#section-4.1.1

# File lib/oauth2-client/grant/authorization_code.rb, line 17
def authorization_path(params={})
  params = params.merge(authorization_params)
  "#{@authorize_path}?#{to_query(params)}"
end
authorization_url(params={}) click to toggle source
# File lib/oauth2-client/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={}) click to toggle source

Retrieve page at authorization path

@param [Hash] opts options

# File lib/oauth2-client/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={}) click to toggle source

Retrieve an access token for a given auth code

@param [String] code refresh token @param [Hash] params additional params @param [Hash] opts options

# File lib/oauth2-client/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_type() click to toggle source
# File lib/oauth2-client/grant/authorization_code.rb, line 11
def grant_type
  "authorization_code"
end
response_type() click to toggle source
# File lib/oauth2-client/grant/authorization_code.rb, line 7
def response_type
  "code"
end
token_path(params={}) click to toggle source

Access Token Request @see tools.ietf.org/html/draft-ietf-oauth-v2-31#section-4.1.3

# File lib/oauth2-client/grant/authorization_code.rb, line 29
def token_path(params={})
  unless params.empty?
    return "#{@token_path}?#{to_query(params)}"
  end
  @token_path
end