从 GMail 获取属性 - OpenID 身份验证

发布于 2024-10-02 14:04:27 字数 1720 浏览 6 评论 0原文

我正在使用 LightOpenID,并尝试获取此 Gmail 身份验证的属性,但它似乎没有在我的个人帐户上返回任何内容,并且我没有收到任何错误。我对 OpenID 非常陌生,希望有人可以帮助我解决这个问题。

我在 validate() 上指定字段并使用 process() 返回它们

我正在使用 OpenID URL:https://www.google.com/accounts/o8/id

    public function show () {
        if ($this->site->tru->post->isRequest() || !$this->site->tru->get->isEmpty('openid_mode')) {
            require_once $this->site->tru->config->get('root.path').'/lib/php/openid.php';
            $this->lightOpenId = new LightOpenID;
            if ($this->validate() || $this->lightOpenId->validate()) {
                $this->process();
            }
        }

        $this->site->addCss('account/login.css');

        $this->site->addJs('account/login.js');

        echo $this->site->tru->display->getTemplate('/site/account/login.tpl');
    }

    public function process () {
        if ($this->lightOpenId->validate()) {
            echo '<pre>'.print_r($this->lightOpenId).'
'.print_r($this->lightOpenId->getAttributes()).'</pre>';
        }
    }

    public function validate () {
        if (!$this->site->tru->post->isEmpty('openid_url')) {
            $this->lightOpenId->identity = $this->site->tru->post->get('openid_url');
            $this->lightOpenId->optional = array('contact/email', 'namePerson', 'contact/postalCode/home', 'contact/country/home');

            header('Location: '.$this->lightOpenId->authUrl());
        }

        return count($this->error) == 0;
    }

I'm utilizing LightOpenID and I'm trying to get attributes for this gmail authentication but it doesn't appear to return anything on my personal account and I get no errors. I'm very new to OpenID and was hoping someone could help me out who's done this before.

I'm specifying the fields on validate() and returning them with process()

I'm using the OpenID URL: https://www.google.com/accounts/o8/id

    public function show () {
        if ($this->site->tru->post->isRequest() || !$this->site->tru->get->isEmpty('openid_mode')) {
            require_once $this->site->tru->config->get('root.path').'/lib/php/openid.php';
            $this->lightOpenId = new LightOpenID;
            if ($this->validate() || $this->lightOpenId->validate()) {
                $this->process();
            }
        }

        $this->site->addCss('account/login.css');

        $this->site->addJs('account/login.js');

        echo $this->site->tru->display->getTemplate('/site/account/login.tpl');
    }

    public function process () {
        if ($this->lightOpenId->validate()) {
            echo '<pre>'.print_r($this->lightOpenId).'
'.print_r($this->lightOpenId->getAttributes()).'</pre>';
        }
    }

    public function validate () {
        if (!$this->site->tru->post->isEmpty('openid_url')) {
            $this->lightOpenId->identity = $this->site->tru->post->get('openid_url');
            $this->lightOpenId->optional = array('contact/email', 'namePerson', 'contact/postalCode/home', 'contact/country/home');

            header('Location: '.$this->lightOpenId->authUrl());
        }

        return count($this->error) == 0;
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌吟 2024-10-09 14:04:27
$openid->identity = 'https://www.google.com/accounts/o8/';

// use the following line to obtain the required details. These are the only details that google mail provides. This is for lightopenid.
$openid->required = array('namePerson/friendly', 'contact/email' , 'contact/country/home', 'namePerson/first', 'pref/language', 'namePerson/last'); 

header('Location: ' . $openid->authUrl());
$openid->identity = 'https://www.google.com/accounts/o8/';

// use the following line to obtain the required details. These are the only details that google mail provides. This is for lightopenid.
$openid->required = array('namePerson/friendly', 'contact/email' , 'contact/country/home', 'namePerson/first', 'pref/language', 'namePerson/last'); 

header('Location: ' . $openid->authUrl());
郁金香雨 2024-10-09 14:04:27

Google 仅回答必需的参数,完全忽略可选参数。

此外,它只能返回以下属性:

contact/country/home
contact/email
namePerson/first
namePerson/last
pref/language

因此 namePersoncontact/postalCode/home 将不起作用。

以上信息仅针对Google,与LightOpenID本身完全无关。

至于库,我建议不要调用 $lightOpenId->validate() 两次。每次调用它时,它都会向提供者发送一个请求,该提供者可能会拒绝第二个请求。

Google answers only to the required parameters, completely ignoring the optional ones.

Also, it can return only following attributes:

contact/country/home
contact/email
namePerson/first
namePerson/last
pref/language

So namePerson and contact/postalCode/home won't work.

The above information are specific to Google, and completely unrelated to LightOpenID itself.

As for the library, I'd advise against calling $lightOpenId->validate() twice. Each time you call it, it sends a request to the provider that might reject the second request.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文