src/Permission/src/OAuth/CredentialMiddleware.php
public function isOAuthAuthenticated(ServerRequestInterface $request)
    {
        $queryParams = $request->getQueryParams();
        $code = $queryParams[GoogleClient::KEY_CODE] ?? null;
        $state = $queryParams[GoogleClient::KEY_STATE] ?? null;

        $this->logger->debug(
            json_encode(
                [
                    'Incoming authorization code: ' . $code,
                    'Incoming state: ' . $state,
                    'Redirect uri: ' . $this->getConfig('redirectUri'),
                ]
            )
        );

        if ($this->getSession($request)->get(GoogleClient::KEY_STATE) != $state) {
            $this->logger->debug("Invalid incoming state");

            return false;
        }

        if (!$this->googleClient->authenticateWithAuthCode($code)) {
            $this->logger->debug("Authentication with authorization code failed");

            return false;
        }

        return true;
    }
public function isOAuthAuthenticated(ServerRequestInterface $request)
    {
        $queryParams = $request->getQueryParams();
        $code = $queryParams[GoogleClient::KEY_CODE] ?? null;
        $state = $queryParams[GoogleClient::KEY_STATE] ?? null;

        $this->logger->debug(
            json_encode(
                [
                    'Incoming authorization code: ' . $code,
                    'Incoming state: ' . $state,
                    'Redirect uri: ' . $this->getConfig('redirectUri'),
                ]
            )
        );

        if ($this->getSession($request)->get(GoogleClient::KEY_STATE) != $state) {
            $this->logger->debug("Invalid incoming state");

            return false;
        }

        if (!$this->googleClient->authenticateWithAuthCode($code)) {
            $this->logger->debug("Authentication with authorization code failed");

            return false;
        }

        return true;
    }
public function isOAuthAuthenticated ( ServerRequestInterface $ request ) { $ queryParams = $ request -> getQueryParams ( ) ; $ code = $ queryParams [ GoogleClient :: KEY_CODE ] ?? null ; $ state = $ queryParams [ GoogleClient :: KEY_STATE ] ?? null ; $ this -> logger -> debug ( json_encode ( [ 'Incoming authorization code: ' . $ code , 'Incoming state: ' . $ state , 'Redirect uri: ' . $ this -> getConfig ( 'redirectUri' ) , ] ) ) ; if ( $ this -> getSession ( $ request ) -> get ( GoogleClient :: KEY_STATE ) != $ state ) { $ this -> logger -> debug ( "Invalid incoming state" ) ; return false ; } if ( ! $ this -> googleClient -> authenticateWithAuthCode ( $ code ) ) { $ this -> logger -> debug ( "Authentication with authorization code failed" ) ; return false ; } return true ; }
Check if user-agent is authenticated

1. Check state according to OAuth 2.0
2. Try to retrieve access token with authorization code

@param ServerRequestInterface $request
@return bool|ResponseInterface
@throws Exception
Check if user - agent is authenticated