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");
}
}