如何从已弃用的Google+登录API迁移到MVC项目中的新Google Identity平台?

问题描述 投票:7回答:2

几天前,我收到了电子邮件通知,谷歌正在弃用其Google+ API:

在2019年3月7日,所有Google+ API和Google+登录都将完全关闭。这将是从1月下旬开始的逐步关闭,早在2019年1月28日,这些API的调用开始间歇性地失败。

我目前在我的ASP.NET MVC项目中使用Google+登录作为外部登录提供程序。貌似,the ASP.NET documentation has not yet been updated (at the time of writing) to take into account this deprecated API

有没有关于AddGoogle()扩展方法是否仍然可以在AuthenticationBuilder中间件中使用的指南,如果是的话,如何?如果没有,我在哪里可以找到有关如何从Google+迁移到Google Identity Platform的指南?

asp.net-core-mvc google-signin
2个回答
6
投票

an open issue on this on the aspnet\docs Github page

这似乎是一个突破性的变化,正如Github上的以下问题所示:

显然,Google OAuth提供商会执行https://www.googleapis.com/plus/v1/people/me调用,该调用用于获取个人资料信息。作为stated by ThoughtHopper,“[t]他当前的代码工作,直到它试图检索userinfo。”

一个temporary workaround was posted by Tratcher,声称适用于ASP.NET 2.0及更高版本:

.AddGoogle(o =>
        {
            o.ClientId = Configuration["google:clientid"];
            o.ClientSecret = Configuration["google:clientsecret"];
            o.UserInformationEndpoint = "https://openidconnect.googleapis.com/v1/userinfo";
            o.ClaimActions.Clear();
            o.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "sub");
            o.ClaimActions.MapJsonKey(ClaimTypes.Name, "name");
            o.ClaimActions.MapJsonKey(ClaimTypes.GivenName, "given_Name");
            o.ClaimActions.MapJsonKey(ClaimTypes.Surname, "family_Name");
            o.ClaimActions.MapJsonKey("urn:google:profile", "profile");
            o.ClaimActions.MapJsonKey(ClaimTypes.Email, "email");
            o.ClaimActions.MapJsonKey("urn:google:image", "picture");
        })

这会更改从中检索信息的端点(不再依赖于Google+),并更改用户信息的映射方式,因为此更改已更改。

从这些问题的关注程度来看,我预计微软会在不久的将来推出更新。在此之前,此修复程序应与禁用的Google+ API一起使用。


1
投票

这个答案只是.NET Framework。

现在应该已经通过Katana项目解决了,所以here回答说:

只需将包Microsoft.Owin.Security.Google更新为版本4.0.1

你可以阅读更多here

或者查看.NET Framework 4+ here的解决方法。

© www.soinside.com 2019 - 2024. All rights reserved.