create saml identity provider in c# with AD integration #125
marcialwushu
started this conversation in
Ideas
Replies: 2 comments
-
using System;
using System.Security.Claims;
using System.Security.Cryptography.X509Certificates;
using System.Web;
using Sustainsys.Saml2;
using Sustainsys.Saml2.Metadata;
using Sustainsys.Saml2.WebSso;
namespace SAMLIdP
{
public class SamlIdentityProvider
{
private readonly Saml2IdentityProvider _idp;
public SamlIdentityProvider()
{
_idp = new Saml2IdentityProvider(new Saml2IdentityProviderOptions
{
EntityId = "https://idp.example.com",
SingleSignOnServiceUrl = new Uri("https://idp.example.com/sso"),
SigningCertificate = new X509Certificate2(...),
MinIncomingSigningAlgorithm = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"
});
}
public void HandleSsoRequest(HttpRequest request, HttpResponse response)
{
_idp.InitiateSso(request, response);
}
public void HandleAuthnResponse(HttpRequest request, HttpResponse response)
{
_idp.ReceiveSsoResponse(request, response);
}
public ClaimsPrincipal GetUserFromAd(string username, string password)
{
// Authenticate the user against AD
// ...
// Create a ClaimsPrincipal with the user's information
var claims = new[]
{
new Claim(ClaimTypes.NameIdentifier, ...),
new Claim(ClaimTypes.Name, ...),
new Claim(ClaimTypes.Email, ...)
};
var identity = new ClaimsIdentity(claims, "saml");
var user = new ClaimsPrincipal(identity);
return user;
}
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
This code creates a basic SAML Identity Provider (IdP) in C#. You'll need to replace the ellipses (...) with appropriate values, such as the certificate used for signing and the metadata of the Service Provider (SP) you are integrating with. You'll also need to implement the authentication against Active Directory (AD) in the GetUserFromAd method. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
To create a SAML Identity Provider in C# with Active Directory (AD) integration, you will need to perform the following steps:
Here's a high-level code example of the steps:
Beta Was this translation helpful? Give feedback.
All reactions