class LeanTesting::OAuth2Handler

Public Class Methods

new(origin) click to toggle source

Constructs an OAuth2Handler instance

Arguments:

origin Client -- Originating client reference
# File lib/Handler/Auth/OAuth2Handler.rb, line 15
def initialize(origin)
        @origin = origin
end

Public Instance Methods

exchangeAuthCode(clientID, clientSecret, grantType, code, redirectURI) click to toggle source

Exceptions:

SDKInvalidArgException if provided clientID param is not a string
SDKInvalidArgException if provided clientSecret param is not a string
SDKInvalidArgException if provided grantType param is not a string
SDKInvalidArgException if provided code param is not a string
SDKInvalidArgException if provided redirectURI param is not a string

Returns:

String -- returns obtained access token string
# File lib/Handler/Auth/OAuth2Handler.rb, line 84
def exchangeAuthCode(clientID, clientSecret, grantType, code, redirectURI)
        if !clientID.is_a? String
                raise SDKInvalidArgException, '`clientID` must be a string'
        elsif !clientSecret.is_a? String
                raise SDKInvalidArgException, '`clientSecret` must be a string'
        elsif !grantType.is_a? String
                raise SDKInvalidArgException, '`grantType` must be a string'
        elsif !code.is_a? String
                raise SDKInvalidArgException, '`code` must be a string'
        elsif !redirectURI.is_a? String
                raise SDKInvalidArgException, '`redirectURI` must be a string'
        end

        params = {
                'grant_type'        => grantType,
                'client_id'         => clientID,
                'client_secret'     => clientSecret,
                'redirect_uri'      => redirectURI,
                'code'                      => code
        }

        req = APIRequest.new(
                @origin,
                '/login/oauth/access_token',
                'POST',
                {
                        'base_uri' => 'https://app.leantesting.com',
                        'params'   => params
                }
        )

        resp = req.exec
        resp['access_token']
end