如何在不请求 SReg 字段的情况下使用 OpenID 来区分/识别用户?

发布于 2024-09-07 03:06:57 字数 1287 浏览 3 评论 0原文

我一直在玩弄 JanRain OpenID PHP 库,主要是遵循我在 ZendZone 上找到的教程。

如何区分用户 - 尤其是 Google 用户,他们最终都使用相同的 OpenID URL,https ://www.google.com/accounts/o8/id

基本上,我现在可以检测到他们有一个 OpenID 帐户...他们已成功通过身份验证...但我的应用程序仍然不知道他们是谁;只是他们经过了身份验证。

为了区分用户,本教程使用“简单注册请求”来请求 OpenID 提供商的用户电子邮件 - 然后使用电子邮件地址来查看这是否是回访用户。

它对我不起作用,并且显然不适用于某些提供商所以当我偶然发现一个函数 getDisplayIdentifier 时,我很兴奋。

require_once "Auth/OpenID/Consumer.php";
require_once "Auth/OpenID/FileStore.php";
// create file storage area for OpenID data
$store = new Auth_OpenID_FileStore('/wtv');
$consumer = new Auth_OpenID_Consumer($store);
$oid_response = $consumer->complete("http://example.com/oir_return");
if ($oid_response->status == Auth_OpenID_SUCCESS) {
    $hopefullyUniqueUserID = $oid_response->getDisplayIdentifier(); // I assumed this would be a relatively permanent way to identify the user...
                                           // I was wrong.
}

不幸的是,几个小时后,getDisplayIdentifier 返回的值发生了变化。

I've been toying with the JanRain OpenID PHP Library, mostly following along with a tutorial I found on ZendZone.

How does one distinguish between users - especially Google users, who all end up using the same OpenID URL, https://www.google.com/accounts/o8/id ?

Basically, I'm at the point where I can detect that they have an OpenID account... that they've successfully authenticated... but my app still doesn't know who they are; only that they authenticated.

To distinguish users, the tutorial uses a "Simple Registration request" to request the user's email of the OpenID provider - and then use email address to see if this is a returning user.

It wasn't working for me, and apparently won't work with some providers so I was excited when I stumbled upon a function getDisplayIdentifier.

require_once "Auth/OpenID/Consumer.php";
require_once "Auth/OpenID/FileStore.php";
// create file storage area for OpenID data
$store = new Auth_OpenID_FileStore('/wtv');
$consumer = new Auth_OpenID_Consumer($store);
$oid_response = $consumer->complete("http://example.com/oir_return");
if ($oid_response->status == Auth_OpenID_SUCCESS) {
    $hopefullyUniqueUserID = $oid_response->getDisplayIdentifier(); // I assumed this would be a relatively permanent way to identify the user...
                                           // I was wrong.
}

Unfortunately, after a couple of hours the value returned by getDisplayIdentifier changes.

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

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

发布评论

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

评论(4

空城之時有危險 2024-09-14 03:06:57

浏览代码,我认为这是您想要的 $oid_response->identity_url 。 从 Google返回

对我来说(尽管在 DotNetOpenAuth 中而不是 php-openid 中),它以https://www.google.com/accounts/o8/id?id=AItOawmqjknrgk6f9cNdPIVxW43GewJPa1ZW4GE

,其中 ID 部分是可重现的希望对我来说是独一无二的。然而,我没有留下几个小时来看看这种情况是否会发生变化,所以如果这是您已经从 getDisplayIdentifier 获得的内容,我深表歉意 - 但浏览一下源代码,它看起来只是使用第一部分,但我不同意PHP专家。

Skimming the code, I think it's $oid_response->identity_url that you want. For me (albeit in DotNetOpenAuth not php-openid) that comes back as

https://www.google.com/accounts/o8/id?id=AItOawmqjknrgk6f9cNdPIVxW43GewJPa1ZW4GE

from Google, where the ID part is reproducible and hopefully unique to me. However I haven't left it a few hours to see if this changes, so apologies if this is what you already had from getDisplayIdentifier - but skimming the source it looks like it'd just use the first part, but then I'm no PHP expert.

三生池水覆流年 2024-09-14 03:06:57

问题在于 Google 的 OpenID 对于每个域都是唯一的;我心不在焉地在 http://www.mysite.comhttp://mysite.com 之间切换,导致 OpenID 身份 url 发生变化!

The problem was that Google's OpenIDs are Unique Per-Domain; I had been absent mindedly alternating between http://www.mysite.com and http://mysite.com, which caused the OpenID identity url to change!

终陌 2024-09-14 03:06:57

为什么不简单地使用 OpenID URL 来识别用户呢?将其视为独一无二,就像电子邮件地址一样。

Why not simply use the OpenID URL to identify users? Consider it unique like an email address.

美羊羊 2024-09-14 03:06:57

根据下面的最后一段,您绝对应该使用响应对象的 identity_url 属性(当然,这是参考 Python 库,但实现非常相似) ):

显示标识符与声明标识符相关,但
两者并不总是相同。显示标识符是
用户应该识别出他们输入的内容,而响应的
声明的标识符(在 L{identity_url} 属性中)可能有额外的
信息以获得更好的持久性。

URL 将被去除其片段以供显示。 XRI 将
显示人类可读的标识符(i-name)而不是
持久标识符(i-number)。

在用户界面中使用显示标识符。使用
L{identity_url} 用于查询您的数据库或授权服务器。

来自 python-openid 文档

According to the last paragraph below, you should definitely use the identity_url attribute of the response object (granted, this is in reference to the Python library, but the implementations are very similar):

The display identifier is related to the Claimed Identifier, but the
two are not always identical. The display identifier is something the
user should recognize as what they entered, whereas the response's
claimed identifier (in the L{identity_url} attribute) may have extra
information for better persistence.

URLs will be stripped of their fragments for display. XRIs will
display the human-readable identifier (i-name) instead of the
persistent identifier (i-number).

Use the display identifier in your user interface. Use
L{identity_url} for querying your database or authorization server.

From the python-openid docs.

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