I am referring to below tutorial to share cookies between 2 different MVC applications running locally,
https://learn.microsoft.com/en-us/aspnet/core/security/cookie-sharing?view=aspnetcore-5.0
BaseApp2 : ruuning at https://localhost:44363/ has below configuration
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();
}
And Subapp1 which should reuse baseapp2 cookies running at https://localhost:44309/ has below configuration,
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();
}
When I login into baseapp2 successfully i could see could see cookie is creating in it's domain. And also it is saved to physical path mentioned in there. But am unable to login to second application using that cookie?
Is anything am missing? Please help.
attached screenshots