An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# ninja Secure.SAML2 v3.0.0
[![NuGet version](https://badge.fury.io/nu/Secure.SAML.svg)](https://badge.fury.io/nu/Secure.SAML) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/NinjaRocks/Secure.SAML/blob/master/License.md)
[![CI](https://github.com/CodeShayk/Secure.SAML2/actions/workflows/CI-Build.yml/badge.svg)](https://github.com/CodeShayk/Secure.SAML2/actions/workflows/CI-Build.yml)
[![CodeQL](https://github.com/CodeShayk/Secure.SAML2/actions/workflows/codeql.yml/badge.svg)](https://github.com/CodeShayk/Secure.SAML2/actions/workflows/codeql.yml)
[![GitHub Release](https://img.shields.io/github/v/release/ninjarocks/Secure.SAML?logo=github&sort=semver)](https://github.com/ninjarocks/Secure.SAML/releases/latest)
[![.Net](https://img.shields.io/badge/.Net-8.0-blue)](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 !! :)