Flarum\Forum\Controller\AbstractOAuth2Controller::handle PHP Method

handle() public method

public handle ( Psr\Http\Message\ServerRequestInterface $request ) : Psr\Http\Message\ResponseInterface | RedirectResponse
$request Psr\Http\Message\ServerRequestInterface
return Psr\Http\Message\ResponseInterface | Zend\Diactoros\Response\RedirectResponse
    public function handle(Request $request)
    {
        $redirectUri = (string) $request->getAttribute('originalUri', $request->getUri())->withQuery('');
        $this->provider = $this->getProvider($redirectUri);
        $session = $request->getAttribute('session');
        $queryParams = $request->getQueryParams();
        $code = array_get($queryParams, 'code');
        $state = array_get($queryParams, 'state');
        if (!$code) {
            $authUrl = $this->provider->getAuthorizationUrl($this->getAuthorizationUrlOptions());
            $session->set('oauth2state', $this->provider->getState());
            return new RedirectResponse($authUrl . '&display=popup');
        } elseif (!$state || $state !== $session->get('oauth2state')) {
            $session->forget('oauth2state');
            echo 'Invalid state. Please close the window and try again.';
            exit;
        }
        $this->token = $this->provider->getAccessToken('authorization_code', compact('code'));
        $owner = $this->provider->getResourceOwner($this->token);
        $identification = $this->getIdentification($owner);
        $suggestions = $this->getSuggestions($owner);
        return $this->authResponse->make($request, $identification, $suggestions);
    }