Creates an access token from a response.

The grant that was used to fetch the response can be used to provide
additional context.

@param  array $response
@param  AbstractGrant $grant
@return AccessToken
428441
protected function createAccessToken(array $response, AbstractGrant $grant)
    {
        return new \Stevenmaguire\OAuth2\Client\Token\AccessToken($response);
    }
274803
protected function makePasswordGrant()
    {
        $grant = new PasswordGrant(
            $this->app->make(Bridge\UserRepository::class),
            $this->app->make(Bridge\RefreshTokenRepository::class)
        );

        $grant->setRefreshTokenTTL(Passport::refreshTokensExpireIn());

        return $grant;
    }
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);
    }
1115971
protected function getAccessToken()
    {
        $response = $this->httpClient
            ->post(
                self::ENDPOINT_ACCESS_TOKEN,
                array(
                    'grant_type'    => 'client_credentials',
                    'client_id'     => $this->config['client_id'],
                    'client_secret' => $this->config['client_secret'],
                    'scope'         => implode(',', $this->config['scopes'])
                )
            )
        ;

        $data = json_decode($response->getContent(), true);

        if (json_last_error() !== JSON_ERROR_NONE) {
            $ex = new HttpResponseException('[access_token] Invalid JSON: '. json_last_error_msg());
            $ex
                ->setResponse($this->httpClient->getLastResponse())
                ->setRequest($this->httpClient->getLastRequest())
            ;

            throw $ex;
        }

        if (false === array_key_exists('access_token', $data)) {
            throw new HttpResponseException('access_token is missing from response. '. $response->getContent());
        }

        return $data;
    }
933669
public function setHttpAuth(string $username, string $password = ''): AbstractApi
    {
        $this->httpAuth['username'] = $username;
        $this->httpAuth['password'] = $password;

        return $this;
    }
459078
protected function findAccessToken(array $response)
    {
        return $this->tokens->find(
            $this->jwt->parse($response['access_token'])->getClaim('jti')
        );
    }
651795
protected function getUserImageUrl(array $response, AccessToken $token)
    {
        $image = $this->getUserImage($response, $token);

        if (isset($image['image']['imageUrl'])) {
            return $image['image']['imageUrl'];
        }
        return null;
    }
16523
private function requestToken(array $key) {
		$s = $this->ss();
		// 2017-06-28
		// «Now that you've acquired an authorization code and have been granted permission by the user,
		// you can redeem the code for an access token to the desired resource,
		// by sending a POST request to the `/token` endpoint.»
		// «Use the authorization code to request an access token»:
		// https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-oauth-code#use-the-authorization-code-to-request-an-access-token
		$c = df_zf_http($this->urlToken())
			->setHeaders(['accept' => 'application/json'])
			->setMethod(C::POST)
			->setParameterPost($this->pCommon() + $key + ['client_secret' => $s->clientPassword()])
		; /** @var C $c */
		/** @var array(string => mixed) $r */
		$this->validateResponse($r = df_json_decode($c->request()->getBody()));
		return $r;
	}
67870
protected function getAccessToken( UserResponseInterface $response )
    {
        $accessToken = $response->getAccessToken();
        switch ( $response->getResourceOwner()->getName() )
        {
            //case UserIdentity::getReadableType( UserIdentity::TYPE_TWITTER ):
            case UserIdentity::getReadableType( UserIdentity::TYPE_YAHOO ):
                return $accessToken['oauth_token'];
            default:
                return $accessToken;
        }
    }
557564
public function acquireTokenWithAsymmetricKey($resource, $credentials)
    {
        $method = Resources::HTTP_POST;
        $headers = [];
        $queryParams = [];
        $postParameters = [];
        $statusCode = Resources::STATUS_OK;

        $postParameters = $this->addPostParameter(
            $postParameters,
            Resources::OAUTH_CLIENT_ASSERTION_TYPE,
            'urn:ietf:params:oauth:client-assertion-type:jwt-bearer'
        );

        $postParameters = $this->addPostParameter(
            $postParameters,
            Resources::OAUTH_RESOURCE,
            $resource
        );

        $postParameters = $this->addPostParameter(
            $postParameters,
            Resources::OAUTH_GRANT_TYPE,
            'client_credentials'
        );

        $postParameters = $this->addPostParameter(
            $postParameters,
            Resources::OAUTH_SCOPE,
            'openid'
        );

        $postParameters = $this->addPostParameter(
            $postParameters,
            Resources::OAUTH_CLIENT_ASSERTION,
            $this->encodeCertificateAsJWT($credentials)
        );

        $response = $this->sendHttp(
            $method,
            $headers,
            $queryParams,
            $postParameters,
            Resources::EMPTY_STRING,
            $statusCode
        );

        $data = $this->dataSerializer->unserialize($response->getBody());

        $accessToken = $data['access_token'];
        $expirationTime = time() + intval($data['expires_in']);
        return new AccessToken($accessToken, $expirationTime);
    }
680322
public function requestToken(Request $request)
    {
        $client = $this->getClient($request);
        $refreshToken = $request->get('refresh_token');

        /** @var TokenInterface $accessToken */
        $accessToken = $this->accessTokenRepository->findOneByClientAndRefreshToken($client, $refreshToken);

        if (! $accessToken instanceof TokenInterface) {
            throw new TokenNotFoundHttpException();
        }
        if ($accessToken->isBlocked()) {
            throw new TokenBlockedHttpException();
        }

        $newAccessToken = $this->accessTokenManager->create($client, $accessToken->getUser());
        if (!$newAccessToken->isValid($this->validator)) {
            return $newAccessToken->getViolations();
        }

        $this->accessTokenManager->save($newAccessToken);

        $tokenFacade = new AccessTokenFacade();
        $tokenFacade->accessToken   = $newAccessToken->getCode();
        $tokenFacade->expiresAt     = $newAccessToken->getExpiredAt();
        $tokenFacade->refreshToken = $newAccessToken->getRefreshCode();

        return $tokenFacade;
    }
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;
    }
236316
protected function createResourceOwner(array $response, AccessToken $token)
	{
		$user = new YouthwebResourceOwner($response);

		return $user->setDomain($this->domain);
	}
1198890
private static function initAccessToken($accessToken)
    {
        if (is_array($accessToken)) {
            return new AccessToken($accessToken);
        } elseif (is_a($accessToken, '\League\OAuth2\Client\Token\AccessToken')) {
            return $accessToken;
        } else {
            return null;
        }
    }
615295
def create_token_response(self, uri, http_method='GET', body=None,
                              headers=None, credentials=None, grant_type_for_scope=None,
                              claims=None):
        """"""
        request = Request(
            uri, http_method=http_method, body=body, headers=headers)

        # 'scope' is an allowed Token Request param in both the "Resource Owner Password Credentials Grant"
        # and "Client Credentials Grant" flows
        # https://tools.ietf.org/html/rfc6749#section-4.3.2
        # https://tools.ietf.org/html/rfc6749#section-4.4.2
        request.scopes = utils.scope_to_list(request.scope)

        request.extra_credentials = credentials
        if grant_type_for_scope:
            request.grant_type = grant_type_for_scope

        # OpenID Connect claims, if provided.  The server using oauthlib might choose
        # to implement the claims parameter of the Authorization Request.  In this case
        # it should retrieve those claims and pass them via the claims argument here,
        # as a dict.
        if claims:
            request.claims = claims

        grant_type_handler = self.grant_types.get(request.grant_type,
                                                  self.default_grant_type_handler)
        log.debug('Dispatching grant_type %s request to %r.',
                  request.grant_type, grant_type_handler)
        return grant_type_handler.create_token_response(
            request, self.default_token_type)
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));
	}
397139
function assertToken($tokenStr)
    {
        if (false === $token = $this->_accessTokens->findByIdentifier((string) $tokenStr))
            throw new exOAuthAccessDenied;


        $accessToken = new AccessTokenEntity(
            new HydrateGetters($token) );

        return $accessToken;
    }