services.AddAuthentication()
.AddGoogle(options =>
{
IConfigurationSection googleAuthNSection =
Configuration.GetSection("Authentication:Google");
options.ClientId = googleAuthNSection["ClientId"];
options.ClientSecret = googleAuthNSection["ClientSecret"];
});
const response = await fetch("/authentication/login/google?returnUrl=" + encodeURIComponent("/"), { method: "POST" });
const result = await response.json();
window.location.href = result.redirectUrl;
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
{
ClientId = "xxxxxxxxxx",
ClientSecret = "xxxxxxxxxx",
CallbackPath = new PathString("/signin-google"),
});
进行以上步骤后,Google身份验证应该可以正常工作。