再会!我目前正在创建一个网站,该网站利用 Google 身份验证来实现内容个性化。我在登录和检索登录用户信息方面没有问题,但当我调用 SignOutAsync() 函数时,.NET 并未完全注销用户,因为用户再次单击“登录”按钮时可以立即登录。清除浏览器缓存后,用户单击“登录”按钮时将被重定向到 Google 登录页面。
Startup.cs 中的服务配置:
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
// Configure authentication service
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = "Google";
})
.AddCookie("Cookies")
.AddGoogle("Google", options =>
{
options.ClientId = Configuration["Authentication:Google:ClientId"];
options.ClientSecret = Configuration["Authentication:Google:ClientSecret"];
});
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddSingleton<IRecommender, OntologyRecommender>();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
Run Code Online (Sandbox Code Playgroud)
Startup.cs 中的中间件配置: …
c# authentication google-authentication asp.net-core-mvc asp.net-core