@param AccessTokenInterface $token

@return ServiceAPI
777004
public function getAPI(TokenInterface $token) {
            $id = $token->getService();
            if (!isset($this->apis[$id])) {
                // TODO: execption
                return null;
            }
            if (is_string($this->apis[$id])) {
                $this->apis[$id] = $this->container->get($this->apis[$id]);
            }

            $this->apis[$id]->setAccessToken($token);
            return $this->apis[$id];
        }
1246633
public function exchange(NostoOAuthToken $token)
    {
        $request = new HttpRequest();
        $request->setContentType(self::CONTENT_TYPE_URL_FORM_ENCODED);
        $request->setPath(HttpRequest::PATH_OAUTH_SYNC);
        $request->setQueryParams(array('access_token' => $token->getAccessToken()));
        $response = $request->get();
        if ($response->getCode() !== 200) {
            throw ExceptionBuilder::fromHttpRequestAndResponse($request, $response);
        }

        $tokens = Token::parseTokens($response->getJsonResult(true), 'api_');
        $account = new Account($token->getMerchantName());
        $account->setTokens($tokens);
        return $account;
    }
1044471
public function setAccessToken($token)
    {
        $accessTokenAttribute = $this->accessTokenAttribute;
        return (is_string($accessTokenAttribute) && !empty($accessTokenAttribute)) ? $this->$accessTokenAttribute = $token : null;
    }
1206685
public function getByAccessToken(AccessTokenEntity $accessToken)
    {
        $result = $this->getConnection()->table('oauth_sessions')
                ->select('oauth_sessions.*')
                ->join('oauth_access_tokens', 'oauth_sessions.id', '=', 'oauth_access_tokens.session_id')
                ->where('oauth_access_tokens.id', $accessToken->getId())
                ->first();

        if (is_null($result)) {
            return;
        }

        return (new SessionEntity($this->getServer()))
               ->setId($result->id)
               ->setOwner($result->owner_type, $result->owner_id);
    }
938410
public function getAccessToken(string $token, string $verifier):AccessToken{
		$request = $this->requestFactory
			->createRequest('POST', Psr7\merge_query($this->accessTokenURL, ['oauth_verifier' => $verifier]))
			->withHeader('Accept-Encoding', 'identity')
		;

		$request = $this->getRequestAuthorization($request, $this->storage->getAccessToken($this->serviceName));

		return $this->parseTokenResponse($this->http->sendRequest($request));
	}
390681
protected function normalizeAccessToken($access_token) {
    if (!isset($access_token['token_type'])) {
      $access_token['token_type'] = 'Bearer';
    }
    if (!isset($access_token['expires_at']) && isset($access_token['expires_in'])) {
      $access_token['expires_at'] = $access_token['expires_in'] + $access_token['request_time'];
    }
    return $access_token;
  }
257235
public static function refreshToken(AccessToken $token, $params = null)
    {
        if ($token->expires_at > new \DateTime()) {
            return $token;
        }

        $requestor = new ApiRequestor(Sumup::$connectBase, true);
        $params = [
            'grant_type' => 'refresh_token',
            'client_id' => self::_getConnectParam('client_id', $params),
            'client_secret' => self::_getConnectParam('client_secret', $params),
            'refresh_token' => $token->refresh_token
        ];
        $response = $requestor->request('post', '/token', $params);

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

        return new AccessToken($response);
    }
1257944
public function recreateForNewAccessToken($accessToken): self
    {
        AccessTokenValidator::assertIsValid($accessToken);

        return new self($this->client, $this->responseTransformer, $this->apiExceptionTransformer, $accessToken);
    }
1228606
public function setAccessToken(AccessToken $token)
    {
        $this->container->get('config')
            ->set('access_token', json_encode($token->jsonSerialize()));
    }
475376
public function authenticatedChannel($token = null)
    {
        $token = $this->getToken($token);

        $channelAPI = new Channels($token);

        return $channelAPI->authenticatedChannel();
    }
932784
public static function createFromAccessTokenEntity(TokenInterface $accessTokenEntity)
    {
        $roles[] = 'ROLE_USER';
        if (($client = $accessTokenEntity->getClient()) instanceof ApiClientInterface ) {
            $roles = array_merge($roles, $client->getRoles());
        }

        if ($user = $accessTokenEntity->getUser()) {
            if ($user instanceof UserInterface) {
                $roles[] = 'ROLE_REAL_USER';
            }

            $roles = array_merge($roles, $user->getRoles());
        }
        $roles = array_unique($roles);

        $token = new self($roles);

        if ($user) {
            $token->setUser($user);
        }

        $token->setAuthenticated(true);
        $token->setAccessToken($accessTokenEntity->getCode());

        return $token;
    }
716251
public function setBearerToken(string $token): Client
    {
        $this->authenticate($token, null, self::AUTH_BEARER);

        return $this;
    }
608266
public function getProvider($accessTokenParams = [], $useCache = true)
    {
        if (!$useCache) {
            $this->provider->getAccessToken($this->type, $accessTokenParams);

            return $this->provider;
        }
        return $this->provider->setAccessToken($this->getToken($accessTokenParams));
    }
500635
private function authenticateRequest(RequestInterface $request, AccessToken $token)
    {
        foreach ($this->provider->getHeaders($token->getToken()) as $name => $value) {
            $request = $request->withHeader($name, $value);
        }

        return $request;
    }
549571
public function getRequestAuthorization(RequestInterface $request, AccessToken $token):RequestInterface{
		$uri = $request->getUri();

		parse_str($uri->getQuery(), $query);

		$parameters = [
			'oauth_consumer_key'     => $this->options->key,
			'oauth_nonce'            => $this->nonce(),
			'oauth_signature_method' => 'HMAC-SHA1',
			'oauth_timestamp'        => (new DateTime)->format('U'),
			'oauth_token'            => $token->accessToken,
			'oauth_version'          => '1.0',
		];

		$parameters['oauth_signature'] = $this->getSignature(
			(string)$uri->withQuery('')->withFragment(''),
			array_merge($query, $parameters),
			$request->getMethod(),
			$token->accessTokenSecret
		);

		if(isset($query['oauth_session_handle'])){
			$parameters['oauth_session_handle'] = $query['oauth_session_handle'];
		}

		return $request->withHeader('Authorization', 'OAuth '.Psr7\build_http_query($parameters, true, ', ', '"'));
	}
507839
public function setAccessTokenStorage(AccessTokenInterface $storage)
    {
        $storage->setServer($this);
        $this->accessTokenStorage = $storage;

        return $this;
    }
981023
public function setToken($token)
    {
        $this->token = $token instanceof Token ? $token : new Token($token);

        return $this;
    }