I have multiple application running under localhost and will be eventually deployed under one domain name like https://myapp.com/
Applications will be like:
https://myapp.com/security
https://myapp.com/app1
https://myapp.com/app2
When user access app1, it logs him in using security app internally. I am using cookie authentication. Now when user moves to app2, I want that app2 uses the cookie created by app1 and doesn't ask to authenticate again.
Startup.cs:
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.AccessDeniedPath = new PathString("/LogUser/RestrictedAccess");
options.LoginPath = new PathString("/LogUser/Login");
options.SlidingExpiration = true;
options.ExpireTimeSpan = TimeSpan.FromMinutes(20);
options.SessionStore = new MemoryCacheTicketStore();
options.Cookie.Name = ".AspNet.SharedCookie";
options.Cookie.Path = "/";
options.ReturnUrlParameter = "OriginalUrl";
});
services.AddSession();
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseAuthentication();
app.UseSession();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}