问题
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