Created
July 2, 2018 06:10
-
-
Save MrSmoke/0045aab98a5025e97331c7f265315119 to your computer and use it in GitHub Desktop.
Saml2 Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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