@param string|null $accessToken

@throws \InvalidArgumentException

@return Api
160033
public static function create($accessToken = '')
    {
        $client = ClientFactory::create();
        $responseTransformer = new ArrayBodyTransformer();
        $apiExceptionTransformer = new GuzzleTransformer();

        return new Api($client, $responseTransformer, $apiExceptionTransformer, $accessToken);
    }
1257944
public function recreateForNewAccessToken($accessToken): self
    {
        AccessTokenValidator::assertIsValid($accessToken);

        return new self($this->client, $this->responseTransformer, $this->apiExceptionTransformer, $accessToken);
    }
1012838
public function validateAccessToken($accessToken)
    {
        $keys        = $this->getJwtVerificationKeys();
        $tokenClaims = (array)JWT::decode($accessToken, $keys, ['RS256']);

        if ($this->getClientId() != $tokenClaims['aud'] && $this->getClientId() != $tokenClaims['appid']) {
            throw new \RuntimeException('The client_id / audience is invalid!');
        }
        if ($tokenClaims['nbf'] > time() || $tokenClaims['exp'] < time()) {
            // Additional validation is being performed in firebase/JWT itself
            throw new \RuntimeException('The id_token is invalid!');
        }

        if ('common' == $this->tenant) {
            $this->tenant = $tokenClaims['tid'];

            $tenant = $this->getTenantDetails($this->tenant);
            if ($tokenClaims['iss'] != $tenant['issuer']) {
                throw new \RuntimeException('Invalid token issuer!');
            }
        } else {
            $tenant = $this->getTenantDetails($this->tenant);
            if ($tokenClaims['iss'] != $tenant['issuer']) {
                throw new \RuntimeException('Invalid token issuer!');
            }
        }

        return $tokenClaims;
    }
243696
public function setAccessToken($accessToken)
    {
        $this->accessToken = $accessToken;
        if ($accessToken instanceof AccessToken) {
            $this->accessToken = $accessToken->getValue();
        }

        return $this;
    }
791544
protected function prepareBaseOptions(string $accessToken): array
    {
        AccessTokenValidator::assertIsValid($accessToken);
        $options = [];
        $options['headers']['Authorization'] = sprintf('Bearer %s', $accessToken);
        $options['base_uri'] = Api::BASE_URI;

        return $options;
    }
593400
public function storeAccessToken(string $service, AccessToken $token):OAuthStorageInterface{
		$this->tokens[$service] = $token;

		return $this;
	}
733169
public static function getValidToken(
        ContextInterface $context,
        AccessToken $token = null,
        array $scopes = null,
        array $options = []
    ): AccessToken
	{
		if ($token === null || !$token->isValid()) {
            $token = AuthenticationHelper::getAccessToken($context, $scopes, $options);
		}

		return $token;
	}
479441
private function getInfos($accessToken)
    {
        $this->logger->debug('Get Infos.');
        $this->initRequest();
        $headers = [
            "Authorization" => "Bearer $accessToken",
        ];
        $userInfoUrl = $this->fcBaseUrl."userinfo?schema=openid";
        $response = \Unirest\Request::get($userInfoUrl, $headers);
        if ($response->code != Response::HTTP_OK) {
            $result_array = $response->body;
            $messageErreur = $result_array['error'];
            $this->logger->error($messageErreur);
            throw new Exception("Erreur lors de la récupération des infos sur le serveur OpenID : ".$messageErreur);
        }
        
        return $response->body;
    }
827969
public function send(EncodedPayload $payload, $accessToken)
    {
        if (empty($this->fluentLogger)) {
            $this->loadFluentLogger();
        }

        $scrubbedPayload = $payload->data();
        
        $success = $this->fluentLogger->post($this->fluentTag, $scrubbedPayload);
        $status = $success ? 200 : 400;
        $info = $success ? 'OK' : 'Bad Request';
        $uuid = $scrubbedPayload['data']['uuid'];

        return new Response($status, $info, $uuid);
    }
277256
private function getEmails($accessToken)
    {

        $ch = curl_init("https://api.github.com/user/emails?access_token={$accessToken}");
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt(
            $ch,
            CURLOPT_HTTPHEADER,
            ['Content-Type: application/json', 'User-Agent: Thruway-WAMP-App']
        );

        $result = curl_exec($ch);

        return json_decode($result);

    }
1021963
private function getAccessToken(AccessToken $invalid = null)
    {
        if (!isset($this->accessToken) || $this->accessToken->hasExpired() || ($invalid && $this->accessToken === $invalid)) {
            $this->accessToken = $this->acquireAccessToken();
            if (is_callable($this->tokenSave)) {
                call_user_func($this->tokenSave, $this->accessToken);
            }
        }

        return $this->accessToken;
    }
655839
public function setOAuthToken(AccessToken $token)
    {
        $this->access_token = $token->getToken();
        $this->access_token_expiration = $token->getExpires();
        $this->refresh_token = $token->getRefreshToken();
        $this->role = $token->getValues()['role'];
    }
598868
public function setAccessToken(?string $accessToken, string $tokenName = null)
    {
        $name = $this->config->getKey($tokenName);
        $cacheKey = $this->creteCacheKey($name);

        if (null === $accessToken) {
            $this->pool->deleteItem($cacheKey);

            return;
        }

        $item = $this->pool->getItem($cacheKey)->set(new AccessToken($name, $accessToken));
        $this->pool->save($item);
    }
220064
public function validateAccessToken($accessToken = null)
	{
		$this->result = $this->http->post($this->getUrl('oauth2/get_token_info'), array(
			'access_token'	=>	null === $accessToken ? $this->accessToken : $accessToken,
		))->json(true);
		if(isset($this->result['error_code']))
		{
			throw new ApiException($this->result['error'], $this->result['error_code']);
		}
		else
		{
			return $this->result['expire_in'] > 0;
		}
	}
430957
public static function getToken($params = null)
    {
        if (!$params) {
            $params = array();
        }
        $requestor = new ApiRequestor(Sumup::$connectBase, true);
        $params['client_id'] = self::_getConnectParam('client_id', $params);
        $params['client_secret'] = self::_getConnectParam('client_secret', $params);
        $response = $requestor->request('post', '/token', $params);

        if ($response->raw->getStatusCode() !== 200) {
            throw new Error\AuthenticationError('Token request error');
        }

        return new AccessToken($response);
    }
725699
public function withAccessToken (AccessToken $token)
    {
        $config = $this->getConfig();
        $this->configureHandlers($config['handler']);
        
        $config['wechat.accessToken'] = $token;
        $config['wechat.developerMode'] = $this->developerMode;
        
        return new static($config);
    }
735820
public function Update($tokenName, $accessLevel, $tokenNameNew = null) {
        return $this->sendRequest('accesstoken/update', array(
                    'tokenName' => $tokenName,
                    'accessLevel' => $accessLevel,
                    'tokenNameNew' => $tokenNameNew
        ));
    }