.net core 2 Google 身份验证登录循环



我正在尝试在.net core 2中使用google进行身份验证,并且已经完成了似乎非常简单的设置:

1) 在启动时Configure(..)中添加app.UseAuthentication();.cs

2) 添加到ConfigureServices(..)启动.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"];
});

为我从 Google Dev 获得的 id 和机密添加了适当的值到我的appsettings.json中。

添加了具有[Authorize]属性的Web API控制器。

在谷歌开发中做了适当的工作,将授权的JavaScript来源设置为http://localhost:50741(我的根)和授权重定向URI到http://localhost:50741/signin-google

结果

转到安全控制器端点会导致重定向到谷歌网页,我可以在其中选择一个谷歌配置文件,我选择一个,它会重定向回http://localhost:50741/signin-google然后立即回到谷歌配置文件屏幕,创建一个无限循环。

我哪里做错了?

如果我将[Authorize]属性更改为[Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme)],一切正常

最新更新