Module: Croudia::API::OAuth

Included in:
Client
Defined in:
lib/croudia/api/oauth.rb

Instance Method Summary collapse

Instance Method Details

#authorize_url(params = {}) ⇒ String

Authorize URL

Parameters:

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

    Query parameters

Options Hash (params):

  • :client_id (String) — default: @client_id

    OAuth client ID

  • :response_type (String) — default: "code"

    OAuth response type

  • :state (String)

Returns:

  • (String)

    Authorize URL

See Also:



14
15
16
17
18
# File 'lib/croudia/api/oauth.rb', line 14

def authorize_url(params={})
  params[:client_id] ||= @client_id
  params[:response_type] ||= 'code'
  connection.build_url('/oauth/authorize', params).to_s
end

#get_access_token(code, params = {}) ⇒ Croudia::AccessToken #get_access_token(params = {}) ⇒ Croudia::AccessToken

Retrieve access_token

Overloads:

  • #get_access_token(code, params = {}) ⇒ Croudia::AccessToken

    Parameters:

    • code (String)

      Authorize code passed from user

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

      Additional query parameters

    Options Hash (params):

    • :client_id (String) — default: @client_id

      OAuth client ID

    • :client_secret (String) — default: @client_secret

      OAuth client secret

    • :grant_type (String) — default: "authorization_code"

      OAuth grant type

  • #get_access_token(params = {}) ⇒ Croudia::AccessToken

    Parameters:

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

      Query parameters

    Options Hash (params):

    • :client_id (String) — default: @client_id

      OAuth client ID

    • :client_secret (String) — default: @client_secret

      OAuth client secret

    • :code (String)

      Code param passed from user

    • :grant_type (String) — default: "authorization_code"

      OAuth grant type

Returns:

See Also:



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/croudia/api/oauth.rb', line 36

def get_access_token(code, params={})
  case code
  when String, Integer
    params[:code] ||= code
  when Hash
    params = code.merge(params)
  end
  params[:client_id] ||= @client_id
  params[:client_secret] ||= @client_secret
  params[:grant_type] ||= 'authorization_code'
  resp = post('/oauth/token', params)
  Croudia::AccessToken.new(resp)
end