I'm implementing an ASP.NET Core webb application using .NET 5.0. We would like to set our own cookie-name and I can't find how to achieve that.
Is there any way to set your own cookie-name when using ITfoxtec SAML 2.0 with .NET 5.0?
I'm implementing an ASP.NET Core webb application using .NET 5.0. We would like to set our own cookie-name and I can't find how to achieve that.
Is there any way to set your own cookie-name when using ITfoxtec SAML 2.0 with .NET 5.0?
The ITfoxtec Identity SAML 2.0 package use the .NET infrastructure as much as possible. The authentication cookie is handled by the ASP.Net core authentication.
You need to implement your own version of Saml2ServiceCollectionExtensions and set the o.Cookie.Name = "somenewname"
.
Like this:
public static IServiceCollection AddSaml2(this IServiceCollection services, string loginPath = "/Auth/Login", bool slidingExpiration = false, string accessDeniedPath = null, ITicketStore sessionStore = null, SameSiteMode cookieSameSite = SameSiteMode.Lax, string cookieDomain = null)
{
services.AddAuthentication(Saml2Constants.AuthenticationScheme)
.AddCookie(Saml2Constants.AuthenticationScheme, o =>
{
o.Cookie.Name = "somenewname";
o.LoginPath = new PathString(loginPath);
o.SlidingExpiration = slidingExpiration;
if(!string.IsNullOrEmpty(accessDeniedPath))
{
o.AccessDeniedPath = new PathString(accessDeniedPath);
}
if (sessionStore != null)
{
o.SessionStore = sessionStore;
}
o.Cookie.SameSite = cookieSameSite;
if (!string.IsNullOrEmpty(cookieDomain))
{
o.Cookie.Domain = cookieDomain;
}
});
return services;
}