elerch / SAML2

Fork of SAML2 library on codeplex. This library removes dependencies on Asp.net
Mozilla Public License 2.0
117 stars 62 forks source link

How to add ACS URL to SAML request? #29

Closed atishayjain closed 4 years ago

atishayjain commented 4 years ago
var config = new Saml2Configuration
            {
                ServiceProvider = new ServiceProvider
                {
                    SigningCertificate = new X509Certificate2(X509Certificate.CreateFromCertFile(certPath)),
                    Server = Settings.Default.SPName,
                    Id = Settings.Default.SPName
                },
                AllowedAudienceUris = new List<Uri>(new[] { new Uri(Settings.Default.SPName) })
            };

            //  The following URLs are based on the defaults used by the middleware above
            config.ServiceProvider.Endpoints.AddRange(new[] {
                                        new ServiceProviderEndpoint(EndpointType.SignOn, "/login", "/login"),
                                        new ServiceProviderEndpoint(EndpointType.Logout, "/logout", "/logout"),
                                        new ServiceProviderEndpoint(EndpointType.Metadata, "/metadata")
                                    });

            config.IdentityProviders.AddByMetadata(metaDataFilePath);
            config.IdentityProviders.First().OmitAssertionSignatureCheck = true;
            config.LoggingFactoryType = "SAML2.Logging.DebugLoggerFactory";

            app.UseSamlAuthentication(new SamlAuthenticationOptions
            {
                AuthenticationType = provider.AuthProviderKey,
                RedirectAfterLogin = provider.CallBackUrl,
                AuthenticationMode = AuthenticationMode.Passive,
                Configuration = config
            });
atishayjain commented 4 years ago

Explored the library, got the solution and it is minor addition

var config = new Saml2Configuration
            {
                ServiceProvider = new ServiceProvider
                {
                    SigningCertificate = new X509Certificate2(X509Certificate.CreateFromCertFile(certPath)),
                    Server = Settings.Default.SPName,
                    Id = Settings.Default.SPName
                },
                AllowedAudienceUris = new List<Uri>(new[] { new Uri(Settings.Default.SPName) })
            };

            //  The following URLs are based on the defaults used by the middleware above
            config.ServiceProvider.Endpoints.AddRange(new[] {
                                        new ServiceProviderEndpoint(EndpointType.SignOn, "/login", "/login", BindingType.Post),
                                        new ServiceProviderEndpoint(EndpointType.Logout, "/logout", "/logout"),
                                        new ServiceProviderEndpoint(EndpointType.Metadata, "/metadata")
                                    });

            config.IdentityProviders.AddByMetadata(metaDataFilePath);
            config.IdentityProviders.First().OmitAssertionSignatureCheck = true;
            config.LoggingFactoryType = "SAML2.Logging.DebugLoggerFactory";

            app.UseSamlAuthentication(new SamlAuthenticationOptions
            {
                AuthenticationType = provider.AuthProviderKey,
                RedirectAfterLogin = provider.CallBackUrl,
                AuthenticationMode = AuthenticationMode.Passive,
                Configuration = config
            });