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
generateAuthLink(clientID, redirectURI, scope = 'read', state = nil)
click to toggle source
Function that generates link for user to follow in order to request authorization code
Arguments:
clientID String -- client ID given at application registration redirectURI String -- URL to be redirected to after authorization scope String -- (optional) comma-separated list of requested scopes (default: 'read') state String -- (optional) random string for MITM attack prevention
Exceptions:
SDKInvalidArgException if provided clientID param is not a string SDKInvalidArgException if provided redirectURI param is not a string SDKInvalidArgException if provided scope param is not a string SDKInvalidArgException if provided state param is not a string
Returns:
String -- returns URL to follow for authorization code request
# File lib/Handler/Auth/OAuth2Handler.rb, line 37 def generateAuthLink(clientID, redirectURI, scope = 'read', state = nil) if !clientID.is_a? String raise SDKInvalidArgException, '`clientID` must be a string' elsif !redirectURI.is_a? String raise SDKInvalidArgException, '`redirectURI` must be a string' elsif !scope.is_a? String raise SDKInvalidArgException, '`scope` must be a string' elsif state && !state.is_a?(String) raise SDKInvalidArgException, '`state` must be a string' end baseURL = 'https://app.leantesting.com/login/oauth/authorize' params = { 'client_id' => clientID, 'redirect_uri' => redirectURI, 'scope' => scope } if state params['state'] = state end baseURL += '?' + Curl::postalize(params) baseURL end