.net core 2 Google身份验证登录循环 [英] .net core 2 Google Authentication login loop
问题描述
我正在尝试在.net core 2中使用google进行身份验证,并且已经完成了为此所需的非常简单的设置:
I am trying to authenticate using google in .net core 2 and have done what seems to be the very simple set up required for this:
1)在startup.cs中将app.UseAuthentication();
添加到Configure(..)
1) Added app.UseAuthentication();
to Configure(..)
in startup.cs
2)已添加到ConfigureServices(..)
startup.cs
2) Added to ConfigureServices(..)
startup.cs
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = GoogleDefaults.AuthenticationScheme;
})
.AddCookie()
.AddGoogle(options =>
{
options.ClientId = Configuration["auth:google:clientid"];
options.ClientSecret = Configuration["auth:google:clientsecret"];
});
在我的appsettings.json
中为从Google Dev中获得的ID和机密添加了适当的值.
Added the appropriate values to my appsettings.json
for the id and secret that I got from Google Dev.
添加了具有[Authorize]
属性的 web-api 控制器.
Added a web-api controller with an [Authorize]
attribute.
在Google dev中完成适当的设置,以将Authorized JavaScript origins设置为http://localhost:50741
(我的根目录),并将Authorized redirect URI设置为http://localhost:50741/signin-google
Done the appropriate stuff in google dev to set the Authorised JavaScript origins to http://localhost:50741
(my root) and Authorised redirect URIs to http://localhost:50741/signin-google
转到安全的控制器端点会导致重定向到google网页,我可以在其中选择一个google个人资料,然后选择一个,然后重定向回到http://localhost:50741/signin-google
,然后立即返回google个人资料屏幕,从而创建无限循环.
Going to the secured controller endpoint results in a redirect to the google webpage where I can choose a google profile, I choose one and it redirects back to http://localhost:50741/signin-google
and then immediately back to the google profiles screen creating an infinite loop.
我哪里出问题了?
推荐答案
如果将[Authorize]
属性更改为[Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme)]
这篇关于.net core 2 Google身份验证登录循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!