Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ITfoxtec SAML 2.0 with NET 5.0- Set cookie name

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?

like image 678
Larserik Elander Avatar asked Jan 26 '26 20:01

Larserik Elander


1 Answers

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;
}   
like image 107
Anders Revsgaard Avatar answered Jan 29 '26 13:01

Anders Revsgaard