Fetches an Auth token

@return Response
@throws ClientException
@throws GuzzleException
6363
protected function tokenRequest(string $route, array $params): Response
    {
        try {
            return $this->client->request('POST', $route, ['json' => $params]);
        } catch (ClientException $exception) {
            if (in_array($exception->getResponse()->getStatusCode(), [401, 403])) {
                throw new ClientException(
                    'Unauthorized SDK Request',
                    $exception->getRequest(),
                    $exception->getResponse(),
                    null,
                    $exception->getHandlerContext()
                );
            }
            throw $exception;
        }
    }
1231211
public static function auth()
    {
        return function (callable $handler) {
            return function (RequestInterface $request, array $options) use ($handler) {
                if (empty($options['http_errors'])) {
                    return $handler($request, $options);
                }
                return $handler($request, $options)->then(
                    function (ResponseInterface $response) use ($request, $handler) {
                        $code = $response->getStatusCode();
                        if ($code == 401 || $code == 403) {
//							do your oauth authorization and retry
                            throw UnauthorizedException::create($request, $response);
                        }

                        return $response;
                    }
                );
            };
        };
    }
29242
def fetch_token(self, **kwargs):
        
        if 'client_secret' not in kwargs:
            kwargs.update(client_secret=self.client_secret)
        return self.session.fetch_token(token_url, **kwargs)
947909
public function acquireUserInfo()
    {
        // Request the userinfo
        $client = new Client(); //GuzzleHttp\Client

        $this->buildHttpHeader();
        $endpoint = $this->userinfo_endpoint;

        try {
            $response = $client->request('GET', $endpoint, [
                'header' => $this->headers,
                'curl' => $this->setGetCurlopts(),
            ]);

            // Get the token and type from the response
            // $this->parseTokenResponse($response);
            return json_decode($response->getBody(), true);

        } catch (\GuzzleException $e) {

            return false;
        }
    }
838770
private function authenticate()
    {
        $try = 0;

        while (true) {
            $try++;

            try {
                $response = $this->soapClient->__soapCall('GetAuthenticationToken', array(array(
                    'authenticationRequest' => $this->authenticationRequest->toArray(),
                )));

                return new AuthenticationTokenResponse(new \DateTime($response->GetAuthenticationTokenResult->DeprecatedDate), $response->GetAuthenticationTokenResult->Key);
            } catch (\SoapFault $e) {
                if (null !== $this->logger) {
                    $this->logger->critical(sprintf('[%] %s', __CLASS__, $e->getMessage()));
                }

                if ($try >= $this->retries) {
                    throw $e;
                }

                // waiting 500ms before next call
                usleep(500000);
            }
        }
    }
1233088
public function getAccessToken()
    {
        try {
            $response = $this->post('/oauth/token')->send();
        } catch (ClientErrorResponseException $e) {
            throw OauthException::factory($e->getRequest(), $e->getResponse());
        }
        return new AccessToken($this, $response);
    }
297067
public function refreshToken()
    {
        $data = $this->parent->performAPICallWithJsonResponse('get', '/refresh_token');

        if (array_key_exists('token', $data)) {
            return $data['token'];
        }

        throw UnauthorizedException::invalidToken();
    }
676798
public function getTokenFromServer()
    {
        $params = [
            'component_appid' => $this->appId,
            'component_appsecret' => $this->secret,
            'component_verify_ticket' => $this->ticket->getTicket(),
        ];

        $http = $this->getHttp();

        $token = $http->parseJSON($http->json(self::API_TOKEN_GET, $params));

        if (empty($token['component_access_token'])) {
            throw new HttpException('Request AccessToken fail. response: '.json_encode($token, JSON_UNESCAPED_UNICODE));
        }

        $token['access_token'] = $token['component_access_token'];

        return $token;
    }
83777
protected function requestToken()
    {
        $this->logger->debug('Requesting a new token');

        $data = [
            'auth' => [
                'passwordCredentials' => [
                    'password' => $this->tenant->getPassword(),
                    'username' => $this->tenant->getUsername(),
                ],
            ],
        ];

        if ($name = $this->tenant->getTenantName()) {
            $data['auth']['tenantName'] = $name;
        }

        try {
            $response = $this->client->request('POST', $this->tenant->getTokenUrl(), [
                RequestOptions::JSON => $data,
            ]);

            return $this->createToken($response->getBody()->getContents());
        } catch (RequestException $e) {
            $this->logger->error(sprintf('Error requesting token: %s', $e->getMessage()));

            throw new TokenException($e->getMessage(), $e->getCode(), $e);
        }
    }
1083236
private function requestToken()
    {
        $tokenResponse = $this->client->request(
            'GET',
            $this->config->getAuthUrl(),
            $this->config->getAuthHeader()
        );


        $this->token = $tokenResponse->getBody()->getContents();

        $this->tokenExpireTime->modify(
            sprintf('+%s seconds', 3600)
        );
    }
427608
public function bindHttpClient()
    {
        $this->app->bind(HttpClient::class, function (Application $app) {
            $client = $app->make('ej:sdk:guzzle');
            $auth = $app->make(Authentication\Authenticator::class);

            return new HttpClient($client, $auth);
        });
    }
466293
public function fetchRequestToken($request)
    {
        $this->getVersion($request);

        $consumer = $this->getConsumer($request);

        // no token required for the initial token request
        $token = null;

        $this->checkSignature($request, $consumer, $token);

        $new_token = $this->dataStore->newRequestToken($consumer);

        return $new_token;
    }
1104137
protected function callback()
	{
		// fetch the response and decode it
		$this->response = \Input::get('opauth', false) and $this->response = unserialize(base64_decode($this->response));

		// did we receive a response at all?
		if ( ! $this->response)
		{
			throw new \OpauthException('no valid response received in the callback');
		}

		// did we receive one, but was it an error
		if (array_key_exists('error', $this->response))
		{
			throw new \OpauthException('Authentication error: the callback returned an error auth response');
		}

		// validate the response
		if ($this->get('auth') === null or $this->get('timestamp') === null or
			$this->get('signature') === null or $this->get('auth.provider') === null or $this->get('auth.uid') === null)
		{
			throw new \OpauthException('Invalid auth response: Missing key auth response components');
		}
		elseif ( ! $this->opauth->validate(sha1(print_r($this->get('auth'), true)), $this->get('timestamp'), $this->get('signature'), $reason))
		{
			throw new \OpauthException('Invalid auth response: '.$reason);
		}
	}
118853
protected function getTokenByClientCredentialsGrant()
    {
        $token = $this->getAuthorizationServer()->getAccessToken('client_credentials', [
            'scope' => $this->config['client_credentials']['scope'],
        ]);

        $this->getFrameworkBridge()->persistClientToken(
            $this->config['client_credentials']['client_id'],
            $token->getToken(),
            $token->getExpires(),
            $token->getValues()['role']
        );

        return $token;
    }
978770
public function fetch()
    {
        $sessionToken = null;
        if (AVUser::getCurrentUser())
        {
            $sessionToken = AVUser::getCurrentUser()->getSessionToken();
        }
        $response = AVClient::_request('GET', '/classes/' . $this->className . '/' . $this->objectId, $sessionToken);
        $this->_mergeAfterFetch($response);
    }
852577
private function getClient() {
        $login = $this->getParam('login');
        $passwordHash = $this->getParam('passwd_hash');
        $token = $this->getParam('token');

        if (empty($token) && (empty($login) || empty($passwordHash))) {
            throw new ConfigurationException(__CLASS__ . ' is not configured properly. Please set "token" or "login" and "passwd_pash" parameters properly.');
        }

        $client = null;
        if (!empty($token)) {
            $client = Client::createFromToken($token);
        }
        else {
            $client = new Client($login);
            $client->setPasswordHash($passwordHash);
        }
        return $client;
    }
48102
public function token()
    {
        try {
            $response = $this->oauthServer->respondToAccessTokenRequest($this->request, new Response());

            $this->pruneTokens();

            return $response;
        } catch (\Exception $e) {
            // Rethrow the exception
            throw $e;
        }
    }