首页 > 解决方案 > AAD 身份验证和 cookie 名称?

问题描述

我正在使用 ASP.Net Core 2.2 MVC。

我的启动添加了 AddAuthentication

我希望能够配置存储 AAD 令牌的 cookie。我尝试在下面添加此代码。但是当我在 Chrome 中运行我的应用程序时,我在开发工具中看不到 cookie 名称。有任何想法吗?

services.ConfigureApplicationCookie(options =>
{
    options.Cookie.Name = "MeAPP";
    options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
    options.SlidingExpiration = true;
});

标签: c#asp.net-coreasp.net-core-identity

解决方案


您可以通过以下方式重命名 cookie 名称:

services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureAD(options => Configuration.Bind("AzureAd", options));

services.Configure<CookieAuthenticationOptions>(AzureADDefaults.CookieScheme, options =>
{
    options.Cookie.Name = "MyCookieName";
});

推荐阅读