это мой контроллер
Код: Выделить всё
{
_logger.LogDebug("LoginGoogle initiated");
await HttpContext.ChallengeAsync(GoogleDefaults.AuthenticationScheme, new AuthenticationProperties
{
RedirectUri = Url.Action("GoogleResponse")
});
}
public async Task GoogleResponse()
{
_logger.LogDebug("GoogleResponse initiated");
var result = await HttpContext.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationScheme);
if (result.Principal != null)
{
_logger.LogDebug("Principal found, extracting claims");
var claims = result.Principal.Identities.FirstOrDefault()?.Claims;
if (claims != null)
{
_logger.LogDebug("Claims found");
var claimValues = claims.Select(claim => new
{
claim.Issuer,
claim.OriginalIssuer,
claim.Type,
claim.Value
});
_logger.LogDebug("Claim values: {@claimValues}", claimValues);
// return Json(claimValues);
return RedirectToAction("Index", "Home", new { area = "" });
}
else
{
_logger.LogWarning("No claims found");
}
}
else
{
_logger.LogWarning("Principal is null");
}
// Handle the case where Principal or Claims are null
_logger.LogDebug("Redirecting to Home due to missing Principal or Claims");
return RedirectToAction("Index", "Home", new { area = "" });
}
Код: Выделить всё
builder.Services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = GoogleDefaults.AuthenticationScheme;
})
.AddCookie()
.AddGoogle(googleOptions =>
{
googleOptions.ClientId = configuration["Authentication:Google:ClientId"];
googleOptions.ClientSecret = configuration["Authentication:Google:ClientSecret"];
googleOptions.Scope.Add("profile");
googleOptions.Scope.Add("email");
});
Я сделал одну вещь: мой файл appsetting.json был скопирован из другого проекта, чтобы он соответствовал порту localhost, зарегистрированному в console.cloud.google.com
Надеюсь, кто-нибудь найдет ответ на эту проблему, потому что я его не нашел.
Подробнее здесь: https://stackoverflow.com/questions/790 ... -principal
Мобильная версия