Sustainsys / Saml2

Saml2 Authentication services for ASP.NET
Other
957 stars 603 forks source link

Multiple SAML2 configuration not working #1402

Closed impathan closed 1 year ago

impathan commented 1 year ago

I have multiple Saml configuration with different schema as below.

.AddSaml2("SCHM-MI", options =>
            {
                options.SPOptions.EntityId = new EntityId("SCHM-MI");
                options.IdentityProviders.Add(new IdentityProvider(
                    new EntityId(".............."), options.SPOptions)
                {
                    MetadataLocation = "...................",
                    LoadMetadata  = true
                });
            })
           .AddSaml2("SCHM-GL",options =>
            {
                options.SPOptions.EntityId = new EntityId("SCHM-GL");
                options.IdentityProviders.Add(new IdentityProvider(
                    new EntityId(".................."), options.SPOptions)
                {
                    MetadataLocation = "............",
                    LoadMetadata = true
                });
            }); 

This is my challenge request on login.

return new ChallengeResult(
                     "SCHM-GL",
                     new AuthenticationProperties
                     {
                         RedirectUri = Url.Action(nameof(LoginCallback), new { returnUrl = "http://localhost:4200/callback" }),
                     });

This configuration is working fine for "SCHM-MI" but not working for "SCHM-GL". I am getting below error on request.

KeyNotFoundException: No Idp with entity id "GL Entity ID" found. Sustainsys.Saml2.Configuration.IdentityProviderDictionary.get_Item(EntityId entityId)

I am using the latest version of Sustainsys.Saml2.AspNetCore2.

Thanks Imrankhan Pathan

AndersAbel commented 1 year ago

If you have multiple schemas you need to assign a unique ModulePath to each of them. The issue here, when both schemas have the same module path, is that the schema "SCHM-MI" picks up all incoming responses since it's registered first.

impathan commented 1 year ago

Thanks, I have added module path and its working fine.