Skip to content

Instantly share code, notes, and snippets.

@MrSmoke
Created July 2, 2018 06:10
Show Gist options
  • Save MrSmoke/0045aab98a5025e97331c7f265315119 to your computer and use it in GitHub Desktop.
Save MrSmoke/0045aab98a5025e97331c7f265315119 to your computer and use it in GitHub Desktop.
Saml2 Example
public async Task<IActionResult> DoChallenge(string returnUrl)
{
var context = await _interaction.GetAuthorizationContextAsync(returnUrl);
var acrTenantValue = context.AcrValues.First(v => v.StartsWith("tenantId:"));
var tentantId = acrTenantValue.Split(':')[1];
// start challenge and roundtrip the return URL and
var props = new AuthenticationProperties
{
RedirectUri = Url.Action("Callback"),
Items =
{
{"returnUrl", returnUrl},
{"tentantId", tentantId}
}
};
return Challenge(props, "saml2");
}
services
.AddAuthentication()
.AddSaml(options =>
{
options.ConfigurationID = properties =>
{
if (properties.Items.TryGetValue("tentantId", out var tentantId))
return tentantId;
return null;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment