1

有没有我可以使用 CakePHP 和 OpenID 组件从 Google 成功获取 OpenId 用户属性(如姓名、电子邮件)的示例?当我尝试添加所需参数时,我收到“您请求的页面无效”。

更多详情

组件:http ://code.42dh.com/openid/

如果我不要求任何“属性”,它工作正常。当我尝试像以下示例中那样添加对必需/可选属性的请求时,我从 Google 收到错误消息:“您请求的页面无效。”

示例(不适合我):http ://cakebaker.42dh.com/2008/02/12/using-the-openid-simple-registration-extension/

根据 1 来源,问题是:

该错误实际上是由于不包括 openid.claimed_id 和 openid.identity 参数而触发的,这些参数必须设置为“ http://specs.openid.net/auth/2.0/identifier_select ”。有了这些设置,我得到另一个错误,也可以通过填写 openid.realm 来解决,其值与 openid.return_to 相同。

Google OpenID:您请求的页面无效

代码

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

1 回答 1

2

看看下面的例子:https ://github.com/cakebaker/openid-component-example/blob/master/app/Controller/UsersController.php

于 2012-04-26T13:47:10.050 回答