https://github.com/codeshayk/secure.saml
Secure.SAML - .Net library to create SAML 2.0 Response with SHA1, SHA256 & SHA512 Signing Algorithms.
https://github.com/codeshayk/secure.saml
saml saml-assertion saml-authentication saml2 saml2-idp sha1-saml sha256-saml sha512-saml single-sign-on sso
Last synced: 7 months ago
JSON representation
Secure.SAML - .Net library to create SAML 2.0 Response with SHA1, SHA256 & SHA512 Signing Algorithms.
- Host: GitHub
- URL: https://github.com/codeshayk/secure.saml
- Owner: CodeShayk
- License: mit
- Archived: true
- Created: 2025-05-13T22:54:01.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2025-05-14T00:13:01.000Z (9 months ago)
- Last Synced: 2025-06-01T18:09:18.609Z (8 months ago)
- Topics: saml, saml-assertion, saml-authentication, saml2, saml2-idp, sha1-saml, sha256-saml, sha512-saml, single-sign-on, sso
- Language: C#
- Homepage:
- Size: 140 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#
Secure.SAML2 v3.0.0
[](https://badge.fury.io/nu/Secure.SAML) [](https://github.com/NinjaRocks/Secure.SAML/blob/master/License.md)
[](https://github.com/CodeShayk/Secure.SAML2/actions/workflows/CI-Build.yml)
[](https://github.com/CodeShayk/Secure.SAML2/actions/workflows/codeql.yml)
[](https://github.com/ninjarocks/Secure.SAML/releases/latest)
[](https://dotnet.microsoft.com/en-us/download/dotnet/8)
## Secure.SAML2 is a .Net library to generate signed SAML 2.0 Response
### Getting Started?
#### i. Installation
Install the latest version of SEcure.SAML2 nuget package with command below.
```
NuGet\Install-Package Secure.SAML2
```
#### ii. Implementation: Using Secure.SAML2
You can use this .Net library to generate signed SAML 2.0 Response with following parameters below-
- `key="Recipient"` is Recipient or Consumer URL
- `key="Issuer"` is value for Issuer Name or domain
- `key="AudienceRestrictions"` is (name/value) dictionary for Audience Restrictions
- `key="NamedId"` is value representing the user Identity or subject
- `key="CustomAttributes"` is (name/value) dictionary for custom attributes to pass to recipient.
- `key="SignatureType"` is whether to sign Response or Assertion.
- `key="signingAlgorithm"` supports SHA1, SHA256 and SHA512 algorithms.
```csharp
var saml = new SAML(Func certificateFactory);
var parameters = new Parameters
{
Issuer = "http://ninjacorp.com",
Recipient = "https://xyz.target-link.co.uk:443/saml/api",
AudienceRestrictions = new[] { "xyz.target-link.co.uk" },
NamedId = "NIN0123456",
NameIdFormat = NameIdFormat.Unspecified, // Default - Unspecified
Attributes = new Dictionary // Optional, Custom payload to recipient.
{
{ "Custom_key", "value" }
},
SignatureType = SignType.Response, // Default - Response
NotOnOrAfterInMins = 10, // Default - 10 minutes
SigningAlgorithm = SigningAlgorithm.SHA512, // Supports - SHA1, SHA256 & SHA512 (default).
SamlId = Guid.Parse("95AD6A84-95C1-4B39-AE5E-FE1E700C406C"), // Optional, defaults to new guid.
AssertionId = Guid.Parse("B3CA912A-4A6B-4F31-9FD8-FC5E55837656"), // Optional, defaults to new guid.
Timestamp = DateTime.Parse("2018-02-27T09:36:44.0665619Z") // Optional, defaults to DateTime.UtcNow
};
var xmlDocument = saml.Create(parameters); // Returns XMLDocument with Signed SAML.
var base64EncodedString = saml.CreateEncoded(parameters); // Returns Base64 encoded string for Signed SAML.
```
Example IoC Registration
```
Container.RegisterType(c=> new SAML(()=> CertificateFactory.Get("signing-cert")));
```
Example Generated SAML :-
```xml
http://ninjacorp.com
SLRX7pQuCZwnqc033B5ohdF7If9zYy8ez1uaDb7E7QKYYHRbIuZ8xDNGTSDI/1WmjkcPiGy8PoCu7l2TflaxVg==
EN/W5jihCeYjUMO3T2I83N6J+gtWsyo1nFCyFacD88TE/00aSATsXC/koju3p+wO1h5xxiGW9mk3kOEOKCUKjekZ7Oub4irCz1xUJ2WmDM1h/+uxb9yFrflnVt8CRuUdfOQpTDAXqS4ENQn26ZsrH9iQ3oPDZcTHqIgwTRWCzR0=
MIIB/DCCAWWgAwIBAgIQ39LYOFEy9K1A+f1T4C/ELzANBgkqhkiG9w0BAQQFADAWMRQwEgYDVQQDEwtYWVogQ29tcGFueTAeFw0wNDEyMzExNzAwMDBaFw0wOTEyMzExNzAwMDBaMBYxFDASBgNVBAMTC1hZWiBDb21wYW55MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3E55S/VquStRieuJ39TM6HkKh47pC+x3XklZ+gmIPHk2XRbUuOCnJunxnesChjDJ2H0tP1usHoPU2jJbfNffEJRrVw8zDavvVqiye4hHGaSL3i7BDOChzKeQY/8yifIMFUIK7DOKwfQDUbJf662gac6u0AmNv/CNdIpECWUHokQIDAQABo0swSTBHBgNVHQEEQDA+gBDHk2UyyDjvEL4gr3OaFlNBoRgwFjEUMBIGA1UEAxMLWFlaIENvbXBhbnmCEN/S2DhRMvStQPn9U+AvxC8wDQYJKoZIhvcNAQEEBQADgYEAIqaguk7RrjeJJtq44DSFatuGtYxASy/MXtdbHhuiYIRNNBgBPB3NWYHVBrZnftBmbHz1Ur61x7ZWYPqezvKhyKZNgHHkbL0O35MHEYNNJhDLdw0QVn4QkZL5MhLHU+8zcaMWTERlQN3rQTAg4paz5oSVDMQyPbUAC/xsquUP44E=
http://ninjacorp.com
NIN0123456
xyz.target-link.co.uk
urn:oasis:names:tc:SAML:2.0:ac:classes:Password
value
```
## Support
If you are having problems, please let me know by [raising a new issue](https://github.com/CodeShayk/Secure.SAML2/issues/new/choose).
## License
This project is licensed with the [MIT license](LICENSE).
## Version History
The main branch is now on .NET 9.0.
| Version | Release Notes |
| -------- | --------|
| [`v4.0.0`](https://github.com/CodeShayk/Secure.SAML2/tree/release/v4.0.0) | [Notes](https://github.com/CodeShayk/Secure.SAML2/releases/tag/v4.0.0) |
| [`v3.0.0`](https://github.com/CodeShayk/Secure.SAML2/tree/release/v3.0.0) | [Notes](https://github.com/CodeShayk/Secure.SAML2/releases/tag/v3.0.0) |
| [`v2.0.0`](https://github.com/CodeShayk/Secure.SAML2/tree/release/v2.0.0) | [Notes](https://github.com/CodeShayk/Secure.SAML2/releases/tag/v2.0.0) |
| [`v1.0.0`](https://github.com/CodeShayk/Secure.SAML2/tree/release/v1.0.1) | [Notes](https://github.com/CodeShayk/Secure.SAML2/releases/tag/v1.0.0) |
## Credits
Thank you for reading. Please fork, explore, contribute and report. Happy Coding !! :)