SampleOwinApplication от Sustainsys не открывает страницу входа в систему единого входа - PullRequest
0 голосов
/ 14 февраля 2019

Я реализую Sustainsys.Saml2 в ASP.NET MVC для нескольких IDP, одним из которых является SAML SSO IDP.Мне нужно переключаться между IDP в зависимости от страны сайта.Я смотрю в SampleOwinApplication.Код приведен ниже.Это только открытие локальной страницы входа, но не входа в систему единого входа.

Я также проверил SampleMvcApplication, однако не уверен, как изменить / переключить IDP там, и он выглядит менее гибким, поскольку мы делаем все из webconfig, а не из кода.

public partial class Startup
{
    public void ConfigureAuth(IAppBuilder app)
    {
        app.CreatePerOwinContext(ApplicationDbContext.Create);
        app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
        app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);         
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),
            Provider = new CookieAuthenticationProvider
            {                      
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                    validateInterval: TimeSpan.FromMinutes(30),
                    regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
            }
        });
        app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
        app.UseSaml2Authentication(CreateSaml2Options());
    }

    private static Saml2AuthenticationOptions CreateSaml2Options()
    {
        var spOptions = CreateSPOptions();
        var Saml2Options = new Saml2AuthenticationOptions(false)
        {
            SPOptions = spOptions
        };
        var idp = new IdentityProvider(new EntityId("https://stubidp.sustainsys.com/Metadata"), spOptions)
            {
                AllowUnsolicitedAuthnResponse = true,
                Binding = Saml2BindingType.HttpRedirect,
                SingleSignOnServiceUrl = new Uri("https://stubidp.sustainsys.com")
            };
        idp.SigningKeys.AddConfiguredKey(
            new X509Certificate2(
                HostingEnvironment.MapPath(
                    "~/App_Data/stubidp.sustainsys.com.cer")));
        Saml2Options.IdentityProviders.Add(idp);
        new Federation("http://localhost:52071/Federation", true, Saml2Options);
        return Saml2Options;
    }

    private static SPOptions CreateSPOptions()
    {
        var attributeConsumingService = new AttributeConsumingService
        {
            IsDefault = true,
            ServiceNames = { new LocalizedName("Saml2", "en") }
        };
        attributeConsumingService.RequestedAttributes.Add(
            new RequestedAttribute("urn:someName")
            {
                FriendlyName = "Some Name",
                IsRequired = true,
                NameFormat = RequestedAttribute.AttributeNameFormatUri
            });
        attributeConsumingService.RequestedAttributes.Add(
            new RequestedAttribute("Minimal"));
        spOptions.AttributeConsumingServices.Add(attributeConsumingService);
        spOptions.ServiceCertificates.Add(new X509Certificate2(
            AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "/App_Data/Sustainsys.Saml2.Tests.pfx"));
        return spOptions;
    }
}
...