@param AccessTokenEntityInterface $accessToken

@throws OAuthServerException
@throws UniqueTokenIdentifierConstraintViolationException

@return RefreshTokenEntityInterface|null
962741
protected function issueRefreshToken(AccessTokenEntityInterface $accessToken)
    {
        $refreshToken = $this->refreshTokenRepository->getNewRefreshToken();

        if ($refreshToken === null) {
            return null;
        }

        $refreshToken->setExpiryDateTime((new DateTime())->add($this->refreshTokenTTL));
        $refreshToken->setAccessToken($accessToken);

        $maxGenerationAttempts = self::MAX_RANDOM_TOKEN_GENERATION_ATTEMPTS;

        while ($maxGenerationAttempts-- > 0) {
            $refreshToken->setIdentifier($this->generateUniqueIdentifier());
            try {
                $this->refreshTokenRepository->persistNewRefreshToken($refreshToken);

                return $refreshToken;
            } catch (UniqueTokenIdentifierConstraintViolationException $e) {
                if ($maxGenerationAttempts === 0) {
                    throw $e;
                }
            }
        }
    }
1368047
protected function getAccessTokenWithRefreshToken(RefreshToken $refreshToken){
		// Send post request to authentication service
		$params = array(
			'client_id' => $this->getConfig()->getClientId(),
			'refresh_token' => $refreshToken->getRefreshToken(),
			'grant_type' => 'refresh_token',
		);
		$response = $this->sendPostRequest("oauth2waitress/oauth2.svc/token", $params);
		$output = $response['output'];
		$httpcode = $response['code'];
		
		switch($httpcode){
			case "200" : 
				$responseObject = json_decode($output);
				if(isset($responseObject->error)){
					// an error occured, the RefreshToken is most likely invalid
					// delete RefreshToken to retrieve new one on next request
					$this->getConfig()->getStorage()->deleteRefreshToken();
					return null;
				}
				// create access token and save it
				$accessToken = new AccessToken(new DateTime(), $responseObject->access_token, $responseObject->token_type, $responseObject->expires_in);
				$this->getConfig()->getStorage()->saveAccessToken($accessToken);
				return $accessToken;
		}
		return null;
	}
1197556
public function createUserVHSConnection($identifier, $accessToken)
    {
        if (!$this->apiVersionIsGreaterThanV3()) {
            throw new EndpointNotSupportedByApiVersionException();
        }

        $params = [
            'identifier' => $identifier,
        ];

        return $this->put('user/vhs', $params, $accessToken);
    }
331608
public function persistNewRefreshToken(RefreshTokenEntityInterface $refreshTokenEntity)
    {
        $this->getEntityManager()->transactional(function(EntityManagerInterface $em) use ($refreshTokenEntity) {
            $em->persist($refreshTokenEntity);
        });
    }
286316
public function validateAccessToken($accessToken = null)
	{
		try
		{
			$this->getOpenID($accessToken);
			return true;
		}
		catch(ApiException $e)
		{
			return false;
		}
	}
1119682
public function refreshToken($refreshToken)
	{
		$response = $this->http->get($this->getUrl('action/openapi/token'), array(
			'client_id'		=>	$this->appid,
			'client_secret'	=>	$this->appSecret,
			'grant_type'	=>	'refresh_token',
			'redirect_uri'	=>	$this->getRedirectUri(),
			'refresh_token'	=>	$refreshToken,
			'dataType'		=>	'json',
		));
		$this->result = $response->json(true);
		if(!isset($this->result['error']))
		{
			return $this->accessToken = $this->result['access_token'];
		}
		else
		{
			throw new ApiException(isset($this->result['error_description']) ? $this->result['error_description'] : '', $response->httpCode());
		}
	}
608248
public static function fetch( $accessToken, $authCheck = true )
    {
        $tokenInfo = null;
        $session = ezcPersistentSessionInstance::get();
        $q = $session->createFindQuery( __CLASS__ );
        $e = $q->expr;

        $q->innerJoin( 'ezprest_clients', 'ezprest_token.client_id', 'ezprest_clients.client_id' );
        if ( $authCheck )
        {
            $q->innerJoin( 'ezprest_authorized_clients', $e->lAnd( $e->eq( 'ezprest_authorized_clients.rest_client_id', 'ezprest_clients.id' ),
                                                                   $e->eq( 'ezprest_authorized_clients.user_id', 'ezprest_token.user_id' ) ) );
        }

        $q->where( $q->expr->eq( 'ezprest_token.id', $q->bindValue( $accessToken ) ) );
        $tokenInfo = $session->find( $q, 'ezpRestToken' );
        if ( !empty( $tokenInfo ) )
        {
            $tokenInfo = array_shift( $tokenInfo );
        }
        else // Empty array. For consistency in result, cast it to null
        {
            $tokenInfo = null;
        }

        return $tokenInfo;
    }
718644
private function getUser(TokenInterface $authenticationToken)
    {
        $user = $authenticationToken->getUser();

        if (is_string($user)) {
            return $user;
        } elseif (method_exists($user, 'getAPIUser')) {
            return $user->getAPIUser()->id;
        }

        return $authenticationToken->getUsername();
    }
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);
    }
1217166
public function setRefreshToken($refreshToken)
    {
        if (is_string($refreshToken)) {
            $refreshToken = new AccessToken($refreshToken, 'refresh_token');
        } elseif (!$refreshToken instanceof AccessToken) {
            throw new \InvalidArgumentException('Invalid refresh token');
        }
        $this->refreshToken = $refreshToken;
    }
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;
    }
1315187
public function getUserInfo($accessToken = null)
	{
		if(null === $this->openid)
		{
			$this->getOpenID($accessToken);
		}
		$this->result = $this->http->get($this->getUrl('user/get_user_info', array(
			'access_token'			=>	null === $accessToken ? $this->accessToken : $accessToken,
			'oauth_consumer_key'	=>	$this->appid,
			'openid'				=>	$this->openid,
		)))->json(true);
		if(isset($this->result['ret']) && 0 != $this->result['ret'])
		{
			throw new ApiException($this->result['msg'], $this->result['ret']);
		}
		else
		{
			return $this->result;
		}
	}
1311173
public function getClient($accessToken) {
        $client = new Google_Client();
        $client->setApplicationName($this->applicationName);
        $client->setAccessType('offline');

        $client->setAccessToken($accessToken);

        // Refresh the token if it's expired.
        if ($client->isAccessTokenExpired()) {
            $client->setAuthConfigFile(Yii::getAlias($this->clientSecretPath));
            $client->refreshToken($client->getRefreshToken());
            $this->saveAccessToken($client->getAccessToken());
        }
        return $client;
    }
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);
    }
491811
public function persistUserToken(AccessToken $token)
    {
        $northstarId = $token->getResourceOwnerId();

        /** @var NorthstarUserContract $user */
        $user = $this->getUser($northstarId);

        // If user hasn't tried to log in before, make them a local record.
        if (! $user) {
            $user = $this->createModel();
            $user->setNorthstarIdentifier($northstarId);
        }

        // And then update their token details.
        $user->setOAuthToken($token);
        $user->save();

        // Finally, tell the guard about the new token if this is the currently
        // logged-in user. (Otherwise, they wouldn't get the new token until
        // the following page load.)
        if (auth()->user() && auth()->user()->getNorthstarIdentifier() === $northstarId) {
            auth()->setUser($user);
        }
    }
362148
public function getUser($accessToken = null, array $options = [])
    {
        if (null === $accessToken) {
            $options['access_token'] = $this->blizzardClient->getAccessToken();
        } else {
            $options['access_token'] = $accessToken;
        }

        return $this->request('/account/user', $options);
    }
700847
public function persistNewAccessToken(AccessTokenEntityInterface $accessTokenEntity)
    {
        $this->getEntityManager()->transactional(function(EntityManagerInterface $em) use ($accessTokenEntity) {
            $em->persist($accessTokenEntity);
        });
    }