Я пытаюсь настроить внешний вход в систему Google на веб-API .Net Core с идентификатором AspNetCore.Однако, когда я вхожу в учетную запись Google, претензии в HttpContext остаются нулевыми.Я не получаю никаких претензий.
Конфигурация Starutp.cs:
services.Configure < CookiePolicyOptions > (options = >{
options.CheckConsentNeeded = context = >true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(CookieAuthenticationDefaults.AuthenticationScheme).AddGoogle("Google", g = >{
g.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
g.ClientId = "";
g.ClientSecret = "";
});
services.AddIdentity < ApplicationUser,
IdentityRole > ().AddEntityFrameworkStores < Context > ().AddDefaultTokenProviders();
services.ConfigureApplicationCookie(options = >options.LoginPath = "/account/google");
var dbConnectionString = Configuration.GetConnectionString("DbConnectionString");
services.AddDbContext < Context > (options = >options.UseLazyLoadingProxies().UseSqlServer(dbConnectionString));
AccountController
// Authorize is a problem cuz this.User has no claims
//[Authorize]
[HttpGet("loginCallback")]
public async Task < IActionResult > LoginCallback(string returnUrl) {
//The add method here takes the claim arr from the context and maps it to a ApplicationUser
await this.userService.Add();
return Redirect("http://localhost:4200/");
}
[HttpGet("google")]
public IActionResult Google() {
string returnUrl = HttpContext.Request.Query["ReturnUrl"];
var callbackUrl = Url.Action("LoginCallback", "Account", new {
returnUrl
});
returnUrl = string.IsNullOrEmpty(returnUrl) ? "/": returnUrl;
return Challenge(new AuthenticationProperties() {
RedirectUri = callbackUrl
},
"Google");
}