.NET Core 2 谷歌认证登录循环问题

3
我正在尝试在.NET Core 2中使用Google进行身份验证,并完成了似乎非常简单的设置:
1) 在startup.cs文件的Configure(..)方法中添加app.UseAuthentication(); 2) 在startup.cs文件的ConfigureServices(..)方法中添加:
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和secret的相应值。

我添加了一个web-api控制器,并添加了[Authorize]属性。

我在Google Dev中完成了适当的设置,将授权的JavaScript来源设置为http://localhost:50741(我的主机名),将授权的重定向URI设置为http://localhost:50741/signin-google

结果

访问安全控制器端点会导致重定向到Google网页,我可以选择Google账户,选择一个之后,就会重定向回http://localhost:50741/signin-google,然后立即返回到Google账户选择页面,形成一个无限循环。

我错在哪里了?


我在启用 SSL 的 IIS Express 上尝试了一下,但问题仍然存在。 - 4imble
1个回答

1
如果我把 [Authorize] 属性改为 [Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme)],那么一切都能正常工作。

不要问我为什么,因为目前我也不知道:),我会就此开一个新的问题。 - 4imble

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接