.net core 2 Google Authentication login loop

馋奶兔 提交于 2020-01-04 04:39:09

问题


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) Added app.UseAuthentication(); to Configure(..) in 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"];
});

Added the appropriate values to my appsettings.json for the id and secret that I got from Google Dev.

Added a web-api controller with an [Authorize] attribute.

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

Result

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.

Where have I gone wrong?


回答1:


It all works fine if I change the [Authorize] attribute to [Authorize(AuthenticationSchemes = CookieAuthenticationDefaults.AuthenticationScheme)]



来源:https://stackoverflow.com/questions/48212025/net-core-2-google-authentication-login-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!