src/snac/server/ServerExecutor.php
/**
     * Check OAuth Authentication
     *
     * Checks the User against OAuth and validates their token.
     *
     * @param \snac\data\User $user The user to validate
     * @return boolean true on success, false on failure
     */
Check OAuth Authentication
Checks the User against OAuth and validates their token.

@param \snac\data\User $user The user to validate
@return boolean true on success, false on failure
Check OAuth Authentication Checks the User against OAuth and validates their token . @param \ snac \ data \ User $user The user to validate @return boolean true on success false on failure
private function checkOAuth($user) {
        $clientId     = \snac\Config::$OAUTH_CONNECTION["google"]["client_id"];
        $clientSecret = \snac\Config::$OAUTH_CONNECTION["google"]["client_secret"];
        $redirectUri  = \snac\Config::$OAUTH_CONNECTION["google"]["redirect_uri"];
        $provider = new \League\OAuth2\Client\Provider\Google(compact('clientId', 'clientSecret', 'redirectUri'));
        try {
            $this->logger->addDebug("Trying to connect to OAuth2 Server to get user details");
            $accessToken = new AccessToken($user->getToken());
            $ownerDetails = $provider->getResourceOwner($accessToken);
            if (strtolower($ownerDetails->getEmail()) != strtolower($user->getEmail())) {
                $this->logger->addDebug("Email mismatch from the user and OAuth details");
                return false;
            }
            $this->logger->addDebug("Successfully got user details from OAuth2 Server");
        } catch (\Exception $e) {
            $this->logger->addDebug("Could not get user details from OAuth2 Server: ".$e->getMessage());
            return false;
        }
        return true;
    }
private function checkOAuth ( $ user ) { $ clientId = \ snac \ Config :: $ OAUTH_CONNECTION [ " google " ] [ " client_id " ] ; $ clientSecret = \ snac \ Config :: $ OAUTH_CONNECTION [ " google " ] [ " client_secret " ] ; $ redirectUri = \ snac \ Config :: $ OAUTH_CONNECTION [ " google " ] [ " redirect_uri " ] ; $ provider = new \ League \ OAuth2 \ Client \ Provider \ Google ( compact ( 'clientId' , 'clientSecret' , 'redirectUri' ) ) ; try { $ this -> logger -> addDebug ( " Trying to connect to OAuth2 Server to get user details " ) ; $ accessToken = new AccessToken ( $ user -> getToken ( ) ) ; $ ownerDetails = $ provider -> getResourceOwner ( $ accessToken ) ; if ( strtolower ( $ ownerDetails -> getEmail ( ) ) != strtolower ( $ user -> getEmail ( ) ) ) { $ this -> logger -> addDebug ( " Email mismatch from the user and OAuth details " ) ; return false ; } $ this -> logger -> addDebug ( " Successfully got user details from OAuth2 Server " ) ; } catch ( \ Exception $ e ) { $ this -> logger -> addDebug ( " Could not get user details from OAuth2 Server:  " . $ e -> getMessage ( ) ) ; return false ; } return true ; }
Check OAuth Authentication
 Checks the User against OAuth and validates their token.
Check OAuth Authentication Checks the User against OAuth and validates their token .
// Google OAuth Settings (from Config) // Change this if you are not using the built-in PHP server // Initialize the provider // This user's token doesn't match the user's email // Could connect using the token, emails matched, so all's good