Last active
August 13, 2018 01:52
-
-
Save rbrayb/f65cf75b896f1df487cc8a945c701298 to your computer and use it in GitHub Desktop.
idsrv4 SAML
This file contains 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
"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" | |
} | |
] | |
} | |
] | |
} | |
] | |
} |
This file contains 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
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(); |
This file contains 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.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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://medium.com/the-new-control-plane/connecting-identityserver-4-idp-and-the-componentspace-saml-v2-0-for-net-core-stack-2cf851d61ab9