【发布时间】:2021-09-18 03:17:24
【问题描述】:
我指的是下面的教程在本地运行的 2 个不同的 MVC 应用程序之间共享 cookie,
https://docs.microsoft.com/en-us/aspnet/core/security/cookie-sharing?view=aspnetcore-5.0
BaseApp2 : 在 https://localhost:44363/ 运行具有以下配置
public void ConfigureServices(IServiceCollection services)
{
DirectoryInfo di = new DirectoryInfo(@"C:\SharedCookies");
services.AddDataProtection()
.PersistKeysToFileSystem(di)
.SetApplicationName("SharedCookieApp");
services.ConfigureApplicationCookie(options =>
{
options.Cookie.Name = ".AspNet.SharedCookie";
});
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie(options =>
{
options.LoginPath = new PathString("/Account/SignIn");
})
.AddOktaMvc(new OktaMvcOptions
{
// Replace these values with your Okta configuration
OktaDomain = Configuration.GetValue<string>("Okta:OktaDomain"),
ClientId = Configuration.GetValue<string>("Okta:ClientId"),
ClientSecret = Configuration.GetValue<string>("Okta:ClientSecret"),
AuthorizationServerId = Configuration.GetValue<string>("Okta:AuthorizationServerId"),
Scope = new List<string> { "openid", "profile", "email" },
});
services.AddControllersWithViews();
}
应该重用在 https://localhost:44309/ 上运行的 baseapp2 cookie 的 Subapp1 具有以下配置,
public void ConfigureServices(IServiceCollection services)
{
DirectoryInfo di = new DirectoryInfo(@"C:\SharedCookies");
services.AddDataProtection()
.PersistKeysToFileSystem(di)
.SetApplicationName("SharedCookieApp");
services.ConfigureApplicationCookie(options =>
{
options.Cookie.Name = ".AspNet.SharedCookie";
options.Cookie.Path = @"C:\SharedCookies";// "/";
});
services.AddControllersWithViews();
}
当我成功登录到 baseapp2 时,我可以看到 cookie 正在其域中创建。并且它也被保存到那里提到的物理路径。但是我无法使用该 cookie 登录到第二个应用程序?
有什么遗漏吗?请帮忙。
附上截图
【问题讨论】:
-
截图中“域”列的值是多少?
标签: c# .net authentication cookies model-view-controller