Skip to content

Instantly share code, notes, and snippets.

@rbrayb
Last active August 13, 2018 01:52
Show Gist options
  • Save rbrayb/f65cf75b896f1df487cc8a945c701298 to your computer and use it in GitHub Desktop.
Save rbrayb/f65cf75b896f1df487cc8a945c701298 to your computer and use it in GitHub Desktop.
idsrv4 SAML
"SAML": {
"$schema": "https://www.componentspace.com/schemas/saml-config-schema-v1.0.json",
"Configurations": [
{
"LocalIdentityProviderConfiguration": {
"Name": "https://IdentityServer4",
"Description": "IdentityServer4",
"SingleSignOnServiceUrl": "http://localhost:5000/SAML/SingleSignOnService",
"SingleLogoutServiceUrl": "http://localhost:5000/SAML/SingleLogoutService",
"ArtifactResolutionServiceUrl": "http://localhost:5000/SAML/ArtifactResolutionService",
"LocalCertificates": [
{
"FileName": "certificates/idp.pfx",
"Password": "password"
}
]
},
"PartnerServiceProviderConfigurations": [
{
"Name": "https://ExampleServiceProvider",
"Description": "Example Service Provider",
"WantAuthnRequestSigned": true,
"SignSamlResponse": true,
"AssertionConsumerServiceUrl": "https://localhost:44360/SAML/AssertionConsumerService",
"SingleLogoutServiceUrl": "https://localhost:44360/SAML/SingleLogoutService",
"ArtifactResolutionServiceUrl": "https://localhost:44360/SAML/ArtifactResolutionService",
"PartnerCertificates": [
{
"FileName": "certificates/sp.cer"
}
]
}
]
}
]
}
app.UseIdentityServer();
// Use SAML middleware.
app.UseSaml();
// Specify the display name and return URL for logout.
app.Use(async (context, next) =>
{
if (context.Request.Path.Value.Equals("/Account/Logout", StringComparison.OrdinalIgnoreCase) &&
string.IsNullOrEmpty(context.Request.Query["logoutId"]))
{
var identityServerInteractionService =
context.RequestServices.GetRequiredService<IIdentityServerInteractionService>();
var logoutMessageStore =
context.RequestServices.GetRequiredService < IMessageStore < LogoutMessage >> ();
var logoutMessage = new Message<LogoutMessage>(new LogoutMessage
{
ClientName = "SAML Service Provider",
PostLogoutRedirectUri = "/SAML/SingleLogoutServiceCompletion"
},
DateTime.UtcNow);
var logoutId = await logoutMessageStore.WriteAsync(logoutMessage);
context.Request.QueryString = context.Request.QueryString.Add("logoutId", logoutId);
}
await next();
});
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
...
services.AddExternalIdentityProviders();
// Add SAML SSO services.
//services.AddSaml(Configuration.GetSection("SAML"));
services.AddSaml(_config.GetSection("SAML"));
// Add SAML Middleware
services.AddSamlMiddleware();
return services.BuildServiceProvider(validateScopes: true);