我正在尝试在.NET Core 2中使用Google进行身份验证,并完成了似乎非常简单的设置:
1) 在startup.cs文件的
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账户选择页面,形成一个无限循环。
我错在哪里了?