PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, January 18, 2022

[FIXED] OpenId Component: getting attributes back from Google using CakePHP

 January 18, 2022     cakephp, cakephp-2.0, components, openid     No comments   

Issue

Is there an example that I can use to successfully get OpenId user attributes (like name, email) back from Google using CakePHP and the OpenID component? When I try and add required parameters, I get a "The page you requested is invalid."

More detail

Component: http://code.42dh.com/openid/

If I don't request any "attributes", it works fine. As soon as I try and add a request for required / optional attributes as in the following example, I get an error from Google: "The page you requested is invalid."

Example (Not working for me): http://cakebaker.42dh.com/2008/02/12/using-the-openid-simple-registration-extension/

According to 1 source, the problem is:

The error was literally triggered by not including the openid.claimed_id and openid.identity parameters, which must be set to "http://specs.openid.net/auth/2.0/identifier_select". With these set, I get another error, which can be resolved by also filling out openid.realm, with the same value as openid.return_to.

Google OpenID: the page you requested is invalid

Code

function openidlogin() {

    $realm = 'http://' . $_SERVER['HTTP_HOST'];
    $returnTo = $realm . '/users/openidlogin';


    $url = "https://www.google.com/accounts/o8/id";
    if ($this->RequestHandler->isPost() && !$this->Openid->isOpenIDResponse()) {
        try {
            $this->Openid->authenticate($url, $returnTo, $realm); // WORKS !!!
            $this->Openid->authenticate($url, 'http://'.$_SERVER['SERVER_NAME'].'/users/login', 'http://'.$_SERVER['SERVER_NAME'], array('email'), array()); // FAILS
        } catch (InvalidArgumentException $e) {
            $this->Session->setFlash("Error: Invalid OpenId");
        } catch (Exception $error) {
            $this->Session->setFlash("Error: " + $error->getMessage());
        }
    } elseif ($this->Openid->isOpenIDResponse()) {

        $response = $this->Openid->getResponse($returnTo);

        if ($response->status == Auth_OpenID_CANCEL) {
            $this->Session->setFlash("Google Login Cancelled");
            $this->redirect(array("controller" => "users", "action" => "login"));
        } elseif ($response->status == Auth_OpenID_FAILURE) {
            $this->Session->setFlash("Veficiation Failed: " . $response->message);
            $this->redirect(array("controller" => "users", "action" => "login"));
        } elseif ($response->status == Auth_OpenID_SUCCESS) {

            $axResponse = Auth_OpenID_AX_FetchResponse::fromSuccessResponse($response);
            debug ($response);
            debug ($axResponse);
            $this->Session->setFlash("Authenticated");
        }
    }

Solution

Have a look at the following example: https://github.com/cakebaker/openid-component-example/blob/master/app/Controller/UsersController.php



Answered By - dhofstet
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing