我已经阅读了大量的 Google 文档和 SO Q/A,但没有运气。我想知道是否有人按照 Google 的建议成功使用了 OpenId 到 OpenId Connect 迁移。
这就是我们以前所做的:
IAuthenticationResponse response = _openid.GetResponse();
if (response != null) {
//omitted for brevity
} else {
IAuthenticationRequest req = _openid.CreateRequest("https://www.google.com/accounts/o8/id");
req.AddExtension(new ClaimsRequest
{
Country = DemandLevel.Request,
Email = DemandLevel.Request,
Gender = DemandLevel.Require,
PostalCode = DemandLevel.Require,
TimeZone = DemandLevel.Require
});
req.RedirectToProvider();
}
这是使用几年前的 DotNetOpenAuth 版本完成的。由于 Google 已弃用 OpenId 身份验证,我们正在尝试转向 OpenID Connect。这里的关键问题是:我能否以某种方式获得 OpenId 标识符(以https://www.google.com/accounts/o8/id?id=xyz)使用最新版本的 DotNetOpenAuth 库或通过任何其他方式?
我已经尝试了最新的 DotNetOpenAuth,我可以让它工作,但它给了我一个新的 ID(这是预期的)。我还通过使用此 URL 尝试了 Javascript 方式(为了可读性换行):
https://accounts.google.com/o/oauth2/auth?
scope=openid%20profile%20email
&openid.realm=http://localhost/palkkac/
&client_id=//here is the client id I created in google developer console
&redirect_uri=http://localhost/palkkac/someaspxpagehere
&response_type=id_token%20token
我检查(使用 Fiddler)我们当前使用旧的 DotNetOpenAuth 代码发送的领域值,它是http://localhost/palkkac/
。我在上面的网址中放置了相同的领域。重定向网址starts与境界值却并不完全相同。
当我重定向到一个解析 id_token 并解密它的简单页面时(使用https://www.googleapis.com/oauth2/v1/tokeninfo?id_token=zyx
端点)我得到这个:
audience "client id is here"
email "[email protected]"
expires_in 3597
issued_at //some numbers here
issued_to "client id is here"
issuer "accounts.google.com"
user_id "here is a sequence of numbers, my id in the OpenID Connect format that is"
verified_email true
因此,这里没有您期望找到的 openid_id 字段的迹象,尽管消息的整个结构似乎与 Google 文档不同,例如没有标题为 sub 的字段。我想知道我是否实际上使用了错误的端点、参数或其他东西?
我一直在阅读的是迁移指南:https://developers.google.com/accounts/docs/OpenID
。我跳过了第 2 步,因为它似乎是一个可选步骤。在步骤 3 中,讨论了 openid_id 字段,我希望首先将其作为概念验证。
我们在 Google 上注册了该应用程序,以便创建客户端 ID 等。现在 Google 开发控制台中还列出了许多允许的重定向 url 以及 javascript 来源。如果这些可能会扰乱系统,请告诉我,我会将其发布到此处以供审核。
旁注:我们应该将我们的应用程序移到严格的防火墙环境后面,我们需要打开端口才能在服务器端执行此操作。因此,最好使用客户端 Javascript 解决方案来访问 Google,结合 HTTPS 并将结果重定向到服务器(除非存在其他问题)。
关于同一问题还有其他资源,尽管所有这些资源似乎在服务器端使用不同的库来完成这项工作,并且似乎没有人尝试使用 Javascript:
- Here (
https://stackoverflow.com/questions/22842475/migrating-google-openid-to-openid-connect-openid-id-does-not-match
)我认为通过将领域设置为与旧的 OpenId2.0 流程中的相同可以解决问题。这似乎不适用于我的情况。
- over hereopenid_id 字段也丢失了,但这里的问题更多的是如何使用 DotNetOpenAuth 以外的库向 Google 请求 id_token。
- and in here让 Google 返回 openid_id 字段似乎也存在类似的问题。