@param AccessTokenEntityInterface $accessToken
@param ClientRepositoryInterface $clientRepository

@throws OAuthServerException
@throws UniqueTokenIdentifierConstraintViolationException

@return RefreshTokenEntityInterface
172770
protected function issueRefreshToken(AccessTokenEntityInterface $accessToken, ClientEntityInterface $client = null)
    {
        $maxGenerationAttempts = self::MAX_RANDOM_TOKEN_GENERATION_ATTEMPTS;

        $refreshToken = $this->refreshTokenRepository->getNewRefreshToken();
        $refreshToken->setAccessToken($accessToken);
        $refreshToken->setUUID($accessToken->getUUID());

        $refresh_expire = $client->getRefreshExpire();

        if(!empty($refresh_expire)){
            $refreshToken->setExpiryDateTime(now()->addMinutes($refresh_expire));
        }else{
            $refreshToken->setExpiryDateTime((new DateTime())->add($this->refreshTokenTTL));
        }


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

                return $refreshToken;
            } catch (UniqueTokenIdentifierConstraintViolationException $e) {
                if ($maxGenerationAttempts === 0) {
                    throw $e;
                }
            }
        }
    }
560443
protected function saveToken(AccessToken $token)
    {
        if ($this->config['api_token'] && $this->config['api_token_type'] === 'access') {
            return;
        }
        foreach ($token->jsonSerialize() as $name => $value) {
            if (isset($this->storageKeys[$name])) {
                $this->session->set($this->storageKeys[$name], $value);
            }
        }
        $this->session->save();
    }
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;
    }
1197556
public function createUserVHSConnection($identifier, $accessToken)
    {
        if (!$this->apiVersionIsGreaterThanV3()) {
            throw new EndpointNotSupportedByApiVersionException();
        }

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

        return $this->put('user/vhs', $params, $accessToken);
    }
590415
protected function createAccessTokenProvider(ProviderRepository $repository)
    {
        Event::listen(AccessTokenCreated::class, function ($event) use ($repository) {
            $provider = config('auth.guards.api.provider');

            $repository->create($event->tokenId, $provider);
        });
    }
95328
public static function signInWithAccessToken( $accesstoken )
	{
		$username = self::getUsernameFromAccessToken( $accesstoken );

		if ( is_null( $username ) ) return false;

		$ip = self::getClientIp();
		$ua = ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ? $_SERVER['HTTP_USER_AGENT'] : '';
		$ts = date("U");
		$cu = get_current_url( true );

		self::$api_session = array( 'username' => $username );

		self::$auth['users'][ $username ]['api_logincount'] = (int) @self::$auth['users'][ $username ]['api_logincount'] + 1;
		self::$auth['users'][ $username ]['api_lastlogin'] = array(
			'ip' => $ip,
			'ua' => $ua,
			'ts' => $ts
		);
		if ( ! is_null( $cu ) ) self::$auth['users'][ $username ]['api_lastlogin']['ur'] = $cu;
		self::save();

		return self::$auth['users'][ $username ];
	}
1361797
public function authenticate(TokenInterface $authenticationToken)
    {
        parent::authenticate($authenticationToken);
        if (!$authenticationToken->getAuthenticationStatus() === TokenInterface::AUTHENTICATION_SUCCESSFUL) {
            return;
        }

        // Force set isAuthenticated to true on authentication manager to update roles needed for entity privileges
        ObjectAccess::setProperty($this->authenticationManager, 'isAuthenticated', true, true);

        $domain = $this->domainRepository->findOneByActiveRequest();
        if ($domain === null) {
            if (!$this->securityContext->hasRole('Neos.Neos:Administrator')) {
                $this->securityLogger->log('No domain found and user has not assigned "Neos.Neos:Administrator", rolling back.', LOG_DEBUG);
                $this->rollback($authenticationToken);
            }
            return;
        }

        $site = $domain->getSite();
        try {
            $site->getName();
            // Site access allowed, continue
        } catch (EntityNotFoundException $e) {
            $this->securityLogger->log('Domain found but user has no access to site, rolling back.', LOG_DEBUG);
            $this->rollback($authenticationToken);
        }
    }
393121
private function refreshAccessToken(Provider $provider, $userId, AccessToken $accessToken)
    {
        // prepare access_token request
        $tokenRequestData = [
            'grant_type' => 'refresh_token',
            'refresh_token' => $accessToken->getRefreshToken(),
            'scope' => $accessToken->getScope(),
        ];

        $response = $this->httpClient->send(
            Request::post(
                $provider->getTokenEndpoint(),
                $tokenRequestData,
                self::getAuthorizationHeader(
                    $provider->getClientId(),
                    $provider->getSecret()
                )
            )
        );

        if (false === $response->isOkay()) {
            $responseData = $response->json();
            if (\array_key_exists('error', $responseData) && 'invalid_grant' === $responseData['error']) {
                // delete the access_token, we assume the user revoked it, that
                // is why we get "invalid_grant"
                $this->tokenStorage->deleteAccessToken($userId, $accessToken);

                return false;
            }

            throw new TokenException('unable to refresh access_token', $response);
        }

        // delete old AccessToken as we'll write a new one anyway...
        $this->tokenStorage->deleteAccessToken($userId, $accessToken);

        $accessToken = AccessToken::fromRefreshResponse(
            $provider,
            $this->dateTime,
            $response->json(),
            // provide the old AccessToken to borrow some fields if the server
            // does not provide them on "refresh"
            $accessToken
        );

        // store the refreshed AccessToken
        $this->tokenStorage->storeAccessToken($userId, $accessToken);

        return $accessToken;
    }
128705
public function refreshAccessToken(TokenInterface $token)
    {
      $refreshToken = $token->getRefreshToken();

      if(empty($refreshToken))
        throw new MissingRefreshTokenException();

      $parameters = array(
        'grant_type'    => 'refresh_token',
        'type'          => 'web_server',
        'client_id'     => $this->credentials->getConsumerId(),
        'client_secret' => $this->credentials->getConsumerSecret(),
        'refresh_token' => $refreshToken,
      );

      require_once 'libx/base.php';

      require_once 'libx/net/http/codes.class.php';
      require_once 'libx/net/rest/client.class.php';
      require_once 'libx/net/rest/request.class.php';
      require_once 'libx/net/rest/response.class.php';

      $request = new \LibXRestRequest($this->getAccessTokenEndpoint(), \LibXRestRequest::REQUEST_METHOD_POST);
      $request->setParameters($parameters);

      $response = new \LibXRestResponse();

      $client = new \LibXRestClient();
      $client->execute($request, $response);

      // Parse token
      $token = $this->parseAccessToken($response->getData());

      // Store token
      $this->storage->storeAccessToken($this->service(), $token);

      // Return token
      return $token;
    }
488209
public function setAccessToken($accessToken)
    {
        $this->accessToken = $accessToken;
        $this->username = '';
        $this->password = '';
        $this->token = '';
        return $this;
    }
366930
public function storeAccessToken($userId, AccessToken $accessToken)
    {
        self::requireSession();
        $_SESSION[\sprintf('_oauth2_token_%s', $userId)][] = $accessToken;
    }
175637
public function setAccessToken($accessToken)
    {
        $this->accessToken = $accessToken;
        $this->client->authenticate($this->accessToken);
    }
941366
public function checkUserSubscriptionToChannel($userIdentifier, $channelIdentifier, $accessToken)
    {
        if ($this->apiVersionIsGreaterThanV3()) {
            if (!is_numeric($userIdentifier)) {
                throw new InvalidIdentifierException('user');
            }

            if (!is_numeric($channelIdentifier)) {
                throw new InvalidIdentifierException('channel');
            }
        }

        return $this->get(sprintf('users/%s/subscriptions/%s', $userIdentifier, $channelIdentifier), [], $accessToken);
    }
673413
protected function refreshIssueToken(array $parameters, ?ClientInterface $determinedClient): ResponseInterface
    {
        if (($refreshValue = $this->refreshGetValue($parameters)) === null) {
            throw new OAuthTokenBodyException(OAuthTokenBodyException::ERROR_INVALID_REQUEST);
        }

        if (($token = $this->refreshGetIntegration()->readTokenByRefreshValue($refreshValue)) === null) {
            throw new OAuthTokenBodyException(OAuthTokenBodyException::ERROR_INVALID_GRANT);
        }

        $clientIdFromToken = $token->getClientIdentifier();
        if ($determinedClient === null) {
            $isClientFromToken = true;
            $determinedClient  = $this->refreshGetIntegration()->readClientByIdentifier($clientIdFromToken);
        } else {
            $isClientFromToken = false;
        }

        // if client didn't provided authentication (but had to) or
        // client associated with the token do not match provided client credentials we throw an exception
        if (($isClientFromToken === true &&
                ($determinedClient->isConfidential() === true || $determinedClient->hasCredentials() === true)) ||
            $determinedClient->getIdentifier() !== $clientIdFromToken
        ) {
            throw new OAuthTokenBodyException(OAuthTokenBodyException::ERROR_INVALID_CLIENT);
        }

        if ($determinedClient->isRefreshGrantEnabled() === false) {
            throw new OAuthTokenBodyException(OAuthTokenBodyException::ERROR_UNAUTHORIZED_CLIENT);
        }

        $isScopeModified = false;
        $scopeList       = null;
        if (($requestedScope = $this->refreshGetScope($parameters)) !== null) {
            // check requested scope is within the current one
            if (empty(array_diff($requestedScope, $token->getScopeIdentifiers())) === false) {
                throw new OAuthTokenBodyException(OAuthTokenBodyException::ERROR_INVALID_SCOPE);
            }
            $isScopeModified = true;
            $scopeList       = $requestedScope;
        }

        $response = $this->refreshGetIntegration()->refreshCreateAccessTokenResponse(
            $determinedClient,
            $token,
            $isScopeModified,
            $scopeList,
            $parameters
        );

        return $response;
    }
342971
function refreshToken($accessToken, $sessionHandle) {
		$code = $this->request ( 'GET', $this->url ( 'AccessToken', '' ), array (
				'oauth_token' => $accessToken,
				'oauth_session_handle' => $sessionHandle 
		) );
		if ($this->response ['code'] == 200) {
			
			$response = $this->extract_params ( $this->response ['response'] );
			
			return $response;
		} else {
			$this->response ['helper'] = "TokenFatal";
			return $this->response;
		}
	}
93753
protected function getExtraParams(AccessTokenEntityInterface $accessToken)
    {
        $params = parent::getExtraParams($accessToken);

        // If this is an OIDC request, pack a new id token into it
        if ($this->isOidcRequest($accessToken->getScopes())) {
            $user = $this->userInfoRepository->getByID($accessToken->getUserIdentifier());

            if ($user) {
                $params['id_token'] = (string) $this->createIdToken($accessToken, $this->claimFactory->createFromUserInfo($user));
            }
        }

        return $params;
    }
843686
public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, $userIdentifier = null)
    {
        $token = new AccessToken();

        $token->setUserIdentifier($userIdentifier);

        return $token;
    }