EOAuth2Service::authenticate PHP Method

authenticate() public method

Authenticate the user.
public authenticate ( ) : boolean
return boolean whether user was successfuly authenticated.
    public function authenticate()
    {
        if (isset($_GET[$this->errorParam])) {
            $error_code = $_GET[$this->errorParam];
            if ($error_code === $this->errorAccessDeniedCode) {
                // access_denied error (user canceled)
                $this->cancel();
            } else {
                $error = $error_code;
                if (isset($_GET[$this->errorDescriptionParam])) {
                    $error = $_GET[$this->errorDescriptionParam] . ' (' . $error . ')';
                }
                throw new EAuthException($error);
            }
            return false;
        }
        // Get the access_token and save them to the session.
        if (isset($_GET['code'])) {
            $code = $_GET['code'];
            $token = $this->getAccessToken($code);
            if (isset($token)) {
                $this->authenticated = true;
                $this->saveAccessToken($token);
            }
        } else {
            // Use the URL of the current page as the callback URL.
            if (isset($_GET['redirect_uri'])) {
                $redirect_uri = $_GET['redirect_uri'];
            } else {
                $server = Yii::app()->request->getHostInfo();
                $path = Yii::app()->request->getUrl();
                $redirect_uri = $server . $path;
            }
            $url = $this->getCodeUrl($redirect_uri);
            Yii::app()->request->redirect($url);
        }
        return $this->getIsAuthenticated();
    }

Usage Example

 /**
  * Authenticate the user.
  * @return boolean whether user was successfuly authenticated.
  */
 public function authenticate()
 {
     if (isset($_GET['error']) && $_GET['error'] == 'user_denied') {
         $this->cancel();
     }
     return parent::authenticate();
 }