@param \Uneak\OAuthClientBundle\OAuth\Grant\GrantInterface $grant
@param int                                                 $authType

@return \Uneak\OAuthClientBundle\OAuth\Token\TokenResponse
432050
public function getAccessToken(GrantInterface $grant) {
			$request = OAuth2::getAccessToken($this->credentialsConfiguration, $this->serverConfiguration, $this->authenticationConfiguration, $grant);
			return $this->buildAccessToken($request);
		}
1339223
public function getOauth2AccessToken($code, $grantType = 'authorization_code')
    {
        $result = $this->httpGet(self::WECHAT_OAUTH2_ACCESS_TOKEN_URL . http_build_query([
            'appid' => $this->appId,
            'secret' => $this->appSecret,
            'code' => $code,
            'grant_type' => $grantType
        ]));
        return isset($result['errmsg']) ? false : $result;
    }
38595
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
    {
        $user = $token->getUser();

        $this->dispatcher->dispatch(self::OAUTH_LOGIN_SUCCESS, new UserEvent($user));

        return $this->authResponseService->authenticateResponse($user,
            new Response($this->twig->render('@StarterKitStart/oauth-success.html.twig')));
    }
329449
public function hasGrantType($grantType)
    {
        $grants = explode(',', $this->Grants);

        return !empty($grants) && in_array($grantType, $grants);
    }
196571
private function validateAuthorizationCode(
        $authCodePayload,
        ClientEntityInterface $client,
        ServerRequestInterface $request
    ) {
        if (time() > $authCodePayload->expire_time) {
            throw OAuthServerException::invalidRequest('code', 'Authorization code has expired');
        }

        if ($this->authCodeRepository->isAuthCodeRevoked($authCodePayload->auth_code_id) === true) {
            throw OAuthServerException::invalidRequest('code', 'Authorization code has been revoked');
        }

        if ($authCodePayload->client_id !== $client->getIdentifier()) {
            throw OAuthServerException::invalidRequest('code', 'Authorization code was not issued to this client');
        }

        // The redirect URI is required in this request
        $redirectUri = $this->getRequestParameter('redirect_uri', $request, null);
        if (empty($authCodePayload->redirect_uri) === false && $redirectUri === null) {
            throw OAuthServerException::invalidRequest('redirect_uri');
        }

        if ($authCodePayload->redirect_uri !== $redirectUri) {
            throw OAuthServerException::invalidRequest('redirect_uri', 'Invalid redirect URI');
        }
    }
1187696
protected function createAccessToken(array $response, AbstractGrant $grant)
  {
    if($grant instanceof FortifiGrant)
    {
      return $grant->handleResponse($response);
    }
    return new AccessToken($response);
  }
133034
public function refreshOauth2AccessToken($refreshToken, $grantType = 'refresh_token')
    {
        $result = $this->httpGet(self::WECHAT_OAUTH2_ACCESS_TOKEN_REFRESH_PREFIX, [
            'appid' => $this->appId,
            'grant_type' => $grantType,
            'refresh_token' => $refreshToken
        ]);
        return !array_key_exists('errcode', $result) ? $result : false;
    }
827616
public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
    {
        try {
            $event = new ApiAuthenticateEvent();

            if (null !== $token->getCredentials()) {
                $event->setUserName($token->getUsername());
                $event->setPassword($token->getCredentials());
                $this->dispatcher->dispatch(ApiAuthenticationEvents::AUTHENTICATE, $event);
            } elseif ($token->getUser() instanceof User) {
                //if we have no password then only way to authenticate is by api key
                $event->setApiKey($token->getUser()->getApiKey());
                $this->dispatcher->dispatch(ApiAuthenticationEvents::API_KEY_AUTHENTICATE, $event);
            }

            $user = $userProvider->loadUserByUsername($token->getUsername());
        } catch (UsernameNotFoundException $e) {
            throw new AuthenticationException($e->getMessage());
        }

        return new UsernamePasswordToken(
            $user,
            $user->getPassword(),
            $providerKey,
            $user->getRoles()
        );
    }
626265
public function getAccessToken($grant = 'client_credentials', array $options = [])
    {
        if($this->accessToken !== null) {
            return $this->accessToken;
        }

        return $this->accessToken = $this->issueAccessToken($grant, $options);
    }
270980
public function checkRestrictedGrantType($clientUuid, $grantType)
    {
        $client = $this->getClientDataMapper()->findByUuid($clientUuid);

        if (! $client instanceof Entity\Client) {
            return false;
        }

        $clientGrantTypes = $client->getGrantTypes();

        if (empty($clientGrantTypes)) {
            return true;
        }

        return in_array($grantType, $clientGrantTypes);
    }
175318
public function get($clientId, $clientSecret = null, $redirectUri = null, $grantType = null)
    {
        $query = null;

        if (!is_null($redirectUri) && is_null($clientSecret)) {
            $query = $this->getConnection()->table('oauth_clients')
                   ->select(
                       'oauth_clients.id as id',
                       'oauth_clients.secret as secret',
                       'oauth_client_endpoints.redirect_uri as redirect_uri',
                       'oauth_clients.name as name')
                   ->join('oauth_client_endpoints', 'oauth_clients.id', '=', 'oauth_client_endpoints.client_id')
                   ->where('oauth_clients.id', $clientId)
                   ->where('oauth_client_endpoints.redirect_uri', $redirectUri);
        } elseif (!is_null($clientSecret) && is_null($redirectUri)) {
            $query = $this->getConnection()->table('oauth_clients')
                   ->select(
                       'oauth_clients.id as id',
                       'oauth_clients.secret as secret',
                       'oauth_clients.name as name')
                   ->where('oauth_clients.id', $clientId)
                   ->where('oauth_clients.secret', $clientSecret);
        } elseif (!is_null($clientSecret) && !is_null($redirectUri)) {
            $query = $this->getConnection()->table('oauth_clients')
                   ->select(
                       'oauth_clients.id as id',
                       'oauth_clients.secret as secret',
                       'oauth_client_endpoints.redirect_uri as redirect_uri',
                       'oauth_clients.name as name')
                   ->join('oauth_client_endpoints', 'oauth_clients.id', '=', 'oauth_client_endpoints.client_id')
                   ->where('oauth_clients.id', $clientId)
                   ->where('oauth_clients.secret', $clientSecret)
                   ->where('oauth_client_endpoints.redirect_uri', $redirectUri);
        }

        if ($this->limitClientsToGrants === true && !is_null($grantType)) {
            $query = $query->join('oauth_client_grants', 'oauth_clients.id', '=', 'oauth_client_grants.client_id')
                   ->join('oauth_grants', 'oauth_grants.id', '=', 'oauth_client_grants.grant_id')
                   ->where('oauth_grants.id', $grantType);
        }

        $result = $query->first();

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

        return $this->hydrateEntity($result);
    }
413585
public function getAccessToken($grant, array $options = [])
    {
        if($grant == 'offline_token') {
            $grant = 'refresh_token';
            if(isset($options["entity_id"])) {
                $options["refresh_token"] = base64_encode($options["entity_id"]);
                unset($options["entity_id"]);
            }
        } elseif ($grant == 'refresh_token') {
            if(isset($options["entity_id"])) {
                $options["refresh_token"] = base64_encode($options["entity_id"]);
                unset($options["entity_id"]);
            }
        }

        $grant = $this->verifyGrant($grant);

        $params = [
            'client_id' => $this->clientId,
            'client_secret' => $this->clientSecret,
            'redirect_uri' => $this->redirectUri,
        ];

        $params = $grant->prepareRequestParameters($params, $options);
        $request = $this->getAccessTokenRequest($params);
        $response = $this->getResponse($request);
        if (gettype($response) == "string") {
            throw new UnauthorizedException("Request error. Didn't get json response back.", $request);
        }
        $prepared = $this->prepareAccessTokenResponse($response);
        $token = $this->createAccessToken($prepared, $grant);

        return $token;
    }
548974
protected function handlesGrant($record, $grantType)
    {
        if (is_array($record->grant_types) && ! in_array($grantType, $record->grant_types)) {
            return false;
        }

        switch ($grantType) {
            case 'authorization_code':
                return ! $record->firstParty();
            case 'personal_access':
                return $record->personal_access_client;
            case 'password':
                return $record->password_client;
            case 'client_credentials':
                return ! empty($record->secret);
            default:
                return true;
        }
    }
437201
public function getAccessToken($grant, array $options = [])
    {
        $grant = $this->verifyGrant($grant);

        $params = [
            'client_id' => $this->clientId,
            'client_secret' => $this->clientSecret,
            'redirect_uri' => $this->redirectUri,
        ];

        $params = $grant->prepareRequestParameters($params, $options);

        // Modify the request for TFA (two-factor authentication) support.
        $request = $this->getAccessTokenRequest($params);
        if ($grant->__toString() === 'password' && isset($options['totp'])) {
            $request = $request->withHeader(self::TFA_HEADER, $options['totp']);
        }

        $response = $this->getParsedResponse($request);
        $prepared = $this->prepareAccessTokenResponse($response);

        return $this->createAccessToken($prepared, $grant);
    }
697225
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
    {
        
        // if AJAX login
        if ( $request->isXmlHttpRequest() ) {

                $array = array( 'success' => true ); // data to return via JSON
                $response = new Response( json_encode( $array ) );
                $response->headers->set( 'Content-Type', 'application/json' );
                return $response;

        } 
        if ($this->hasRole('ROLE_ADMIN', $token->getUser()) || $this->hasRole('ROLE_SUPER_ADMIN', $token->getUser())) {
            return new RedirectResponse($this->container->get('router')->generate('admin_default_dashboard'));
        } elseif ($this->hasRole('ROLE_COMPANY', $token->getUser())) {
            return new RedirectResponse($this->container->get('router')->generate('company_default_dashboard'));
        } else {
            // set context with GET method of the previous ajax call
            $context = $this->container->get('router')->getContext();
            $currentMethod = $context->getMethod();
            $context->setMethod('GET');

            // match route
            $referer = $this->getRefererPath($request);
            $match = $this->container->get('router')->match($referer);
            // set back original http method
            $context->setMethod($currentMethod);
            
            if (isset($match['_route']) && $match['_route'] == 'ecommerce_checkout_identification' && isset($match['_locale'])) {
                return new RedirectResponse($this->container->get('router')->generate('ecommerce_checkout_deliveryinfo', array('_locale' => $match['_locale'])));
            }
            return new RedirectResponse($this->container->get('router')->generate('index'));
        }
    }
334078
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $requestHandler = $request->getAttributes()['requestHandler'][2]['handler'] ?? '';
        $service = App::getBean(AuthServiceInterface::class);
        if (!$service instanceof AuthServiceInterface) {
            throw new AuthException(ErrorCode::POST_DATA_NOT_PROVIDED, 'AuthService should implement Swoft\Auth\Mapping\AuthServiceInterface');
        }
        if (!$service->auth($requestHandler, $request)) {
            throw new AuthException(ErrorCode::ACCESS_DENIED);
        }
        $response = $handler->handle($request);
        return $response;
    }
316559
protected function requestAccessToken($grantType = 'client_credential')
    {
        $result = $this->httpGet(static::WECHAT_ACCESS_TOKEN_URL, [
            'appid' => $this->appId,
            'secret' => $this->appSecret,
            'grant_type' => 'client_credential'
        ]);
        if (isset($result['access_token'])) {
            $result['expire'] = $result['expires_in'] + (int)YII_BEGIN_TIME;
            return $result;
        }
        return false;
    }