Module: GogoKit::Client::OAuth

Includes:
Utils
Included in:
GogoKit::Client
Defined in:
lib/gogokit/client/oauth.rb

Overview

OAuth authentication methods for GogoKit::Client

Instance Method Summary collapse

Methods included from Utils

#object_from_response

Instance Method Details

#get_access_token(grant_type, options = {}) ⇒ GogoKit::OAuthToken

Get an OAuth access token

Parameters:

  • grant_type (String)

    The grant type to use to get the token

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

    Token request information

Returns:

See Also:



72
73
74
75
76
77
78
79
# File 'lib/gogokit/client/oauth.rb', line 72

def get_access_token(grant_type, options = {})
  object_from_response(GogoKit::OAuthToken,
                       GogoKit::OAuthTokenRepresenter,
                       :post,
                       oauth_token_endpoint,
                       body: token_request_body(grant_type, options),
                       headers: token_request_headers)
end

#get_authorization_code_access_token(code, redirect_uri, scopes, options = {}) ⇒ Object

Requests an access token that will provide access to user-specific data (sales, sellerlistings, webhooks, purchases, etc) applications return URL. authorization code is sent. This must match the URL registered for your application. needed.

Parameters:

  • code (String)

    The authorization code that was sent to your

  • redirect_uri (String)

    Application redirect URL where the

  • scopes (Array)

    The scopes that specify the type of access that is

See Also:



37
38
39
40
41
42
43
44
45
46
# File 'lib/gogokit/client/oauth.rb', line 37

def get_authorization_code_access_token(code,
                                        redirect_uri,
                                        scopes,
                                        options = {})
  scope_value = scopes.nil? ? '' : scopes.join(' ')
  merged_options = options.merge(code: code,
                                 redirect_uri: redirect_uri,
                                 scope: scope_value)
  get_access_token('authorization_code', merged_options)
end

#get_authorization_url(redirect_uri, scopes, state = nil) ⇒ Object

Gets the URL where applications can obtain a users consent to make API calls on their behalf. authorization code is sent. This must match the URL registered for your application. needed. authorize request and the callback.

Parameters:

  • redirect_uri (String)

    Application redirect URL where the

  • scopes (Array)

    The scopes that specify the type of access that is

  • state (String) (defaults to: nil)

    An opaque value used to maintain state between the

See Also:



21
22
23
24
25
# File 'lib/gogokit/client/oauth.rb', line 21

def get_authorization_url(redirect_uri, scopes, state = nil)
  scope_value = scopes.nil? ? '' : scopes.join('%20')
  "#{authorization_endpoint}?client_id=#{client_id}&response_type=code&" \
  "redirect_uri=#{redirect_uri}&scope=#{scope_value}&state=#{state}"
end

#get_client_access_token(options = {}) ⇒ GogoKit::OAuthToken

Get an OAuth access token for an application.

Parameters:

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

    Token request information

Returns:

See Also:



53
54
55
# File 'lib/gogokit/client/oauth.rb', line 53

def get_client_access_token(options = {})
  get_access_token('client_credentials', options)
end

#get_refresh_token(token, options = {}) ⇒ Object

Obtain additional access tokens in order to prolong access to a users data

Parameters:



60
61
62
63
64
# File 'lib/gogokit/client/oauth.rb', line 60

def get_refresh_token(token, options = {})
  merged_options = options.merge(refresh_token: token.refresh_token,
                                 scope: token.scope)
  get_access_token('refresh_token', merged_options)
end