Sustainsys.Saml2.Owin: So rufen Sie UseSaml2Authentication mit mehreren Sätzen verschiedener Saml2AuthenticationOptions C#

Ein Treffpunkt für C#-Programmierer
Guest
 Sustainsys.Saml2.Owin: So rufen Sie UseSaml2Authentication mit mehreren Sätzen verschiedener Saml2AuthenticationOptions

Post by Guest »

Ich bin neu bei Saml2, also verzeihen Sie mir bitte, wenn ich die Terminologie nicht ganz richtig verstehe. Ich wurde mit der Implementierung von SSO in unserer Anwendung beauftragt. Ich habe eine ähnliche Situation wie diese Frage. In unserer Anwendung gibt ein Benutzer seinen Benutzernamen ein und ich muss mich dann beim entsprechenden IdP für diesen Benutzer authentifizieren. Allerdings ist Saml2AuthenticationOptions.SPOptions.EntityId für jeden unterschiedlich, ebenso wie IdentityProvider.EntityId.
Also, was ich versucht habe, war so etwas wie

Code: Select all

private static Dictionary _saml2OptionsDict = new Dictionary();

public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

app.UseCookieAuthentication(new CookieAuthenticationOptions());

app.Properties["host.AppName"] = "AppName";

ConfigureIdentityProvider("provider1", "SamlEntityId.1", "IdPEntityId.1", "MetadataUrl.1", "ECMCLoantrackerDev.cer");
ConfigureIdentityProvider("provider2", "SamlEntityId.2", "IdPEntityId.2", "MetadataUrl.2", "LT Test app.cer");

app.UseSaml2Authentication(GetSaml2Options(("provider1")));
app.UseSaml2Authentication(GetSaml2Options(("provider2")));
}

private void ConfigureIdentityProvider(string providerKey, string samlEntityIdKey, string idpEntityIdKey, string metadataUrlKey, string certName)
{
var saml2Options = new Saml2AuthenticationOptions(false)
{
SPOptions = new Sustainsys.Saml2.Configuration.SPOptions
{
EntityId = new Sustainsys.Saml2.Metadata.EntityId(ConfigurationManager.AppSettings[samlEntityIdKey]),
ReturnUrl = new Uri(ConfigurationManager.AppSettings["ExternalLoginCallbackUrl"])
}
};

var idp = new Sustainsys.Saml2.IdentityProvider(
new Sustainsys.Saml2.Metadata.EntityId(ConfigurationManager.AppSettings[idpEntityIdKey]),
saml2Options.SPOptions)
{
MetadataLocation = ConfigurationManager.AppSettings[metadataUrlKey],
Binding = Sustainsys.Saml2.WebSso.Saml2BindingType.HttpRedirect
};

idp.SigningKeys.AddConfiguredKey(
new X509Certificate2(
HostingEnvironment.MapPath(
"~/App_Data/" + certName)));

saml2Options.IdentityProviders.Add(idp);

_saml2OptionsDict[providerKey] = saml2Options;
}

public static Saml2AuthenticationOptions GetSaml2Options(string providerKey)
{
return _saml2OptionsDict.ContainsKey(providerKey) ? _saml2OptionsDict[providerKey] : null;
}

Ich glaube, ich muss dann anhand des Benutzernamens nach den zu verwendenden Optionen suchen und diese an die Herausforderung weitergeben, etwa

Code: Select all

var saml2Options = Startup.GetSaml2Options(provider);
HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = "/Account/ExternalLoginCallback" }, saml2Options.AuthenticationType);
Aber ich muss nicht mehr mehrmals UseSaml2Authentication aufrufen. Wenn ich nur das eine oder andere mache, ist alles in Ordnung, außer natürlich, dass sich die Benutzer nicht authentifizieren können. Ein IdP funktioniert also, aber nicht mehrere.
Wie gesagt, ich bin in diesem Bereich nur ein Anfänger. Ist das, was ich versuche, überhaupt möglich?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post