ITfoxtec.Identity.Saml2

repository·main·Indexed 43 days ago

https://github.com/itfoxtec/itfoxtec.identity.saml2

An open-source SAML 2.0 library for .NET applications, enabling them to function as Service Providers, Relying Parties, or Identity Providers. It provides comprehensive support for authentication flows, bindings (Redirect, POST, Artifact, SOAP), message handling, and cryptography. The library includes specialized integration packages for ASP.NET Core MVC (ITfoxtec.Identity.Saml2.MvcCore) and ASP.NET MVC 5 (.NET Framework) (ITfoxtec.Identity.Saml2.Mvc).

Tokens
1.9K
Snippets
4
Records
11
Agent score
55%

What's inside ITfoxtec.Identity.Saml2

  1. Overview of SAML 2.0 capabilities in ITfoxtec.Identity.Saml2

    main

    The library provides comprehensive support for SAML 2.0 features, including:

    • Authentication Flows: SP-initiated and IdP-initiated sign-on, login, logout, and single logout.
    • Bindings & Protocols: Redirect Binding, POST Binding, Artifact Binding, and SOAP support.
    • Message Handling: Authn Request, Authn Response, Logout Request, and Logout Response.
    • Security: Message signing, signature validation, and encrypted assertions.
    • Cryptography:
      • Signing: RSA SHA1, SHA256, SHA384, SHA512, RSA-PSS SHA256, and ECDSA (SHA256, SHA384, SHA512).
      • Encryption: AES-CBC, AES-GCM, RSA key transport, and XML Encryption 1.1 RSA-OAEP.
    • Metadata: SAML metadata generation and handling.
    • Interoperability: Tested with Microsoft Entra ID (Azure AD), AD FS, Azure AD B2C, and various Danish identity providers (MitID, etc.).
  2. What ITfoxtec.Identity.Saml2.Mvc provides

    main

    The ITfoxtec.Identity.Saml2.Mvc package is designed for .NET Framework MVC applications that need to implement SAML 2.0 directly. It provides:

    • Request Conversion: Converts ASP.NET MVC requests into SAML 2.0 requests.
    • ActionResult Helpers: Specialized helpers for handling Redirect, POST, Artifact, SOAP, and metadata responses.
    • MVC Integration Points: Ready-to-use endpoints for SAML 2.0 login, Assertion Consumer Service (ACS), Single Logout (SLO), and metadata.

    It supports various security features including message signing, signature validation, encrypted assertions, and multiple bindings (Redirect, POST, Artifact).

  3. Choose between direct integration and FoxIDs bridge

    main

    Decide how to implement SAML 2.0 based on your application's existing architecture:

    Direct Integration

    Use the ITfoxtec.Identity.Saml2 library when you need to implement the SAML 2.0 protocol directly within your .NET or ASP.NET application code. This is ideal if your application is intended to act as a Service Provider (SP), Relying Party (RP), or Identity Provider (IdP) natively.

    FoxIDs Bridge

    Use FoxIDs if your application already supports OpenID Connect or WS-Federation and you want to avoid adding SAML 2.0 logic to your codebase. FoxIDs acts as a protocol bridge (e.g., SAML 2.0 to OpenID Connect), handling the SAML complexities externally while your application continues using its existing protocol.

  4. Deciding between direct integration and FoxIDs bridge

    main

    When implementing SAML 2.0, you have two primary architectural paths:

    1. Direct Integration (Use ITfoxtec.Identity.Saml2.Mvc)

    Use this approach when you want to implement the SAML 2.0 protocol directly within your ASP.NET MVC application code.

    2. FoxIDs Bridge

    Use FoxIDs if your application already uses OpenID Connect or WS-Federation and you want to avoid adding another protocol implementation. FoxIDs acts as an external identity bridge that handles the SAML 2.0 connection, allowing your application to continue using its existing protocol.

    Choose FoxIDs if you need:

    • A SAML 2.0 to OpenID Connect or WS-Federation bridge.
    • To avoid changing an application that already supports OIDC or WS-Federation.
    • To move protocol translation, certificates, and metadata management outside of your application code.
    • Architecture guidance for complex federation setups or SAML 2.0 migrations.
  5. Decide between direct integration and FoxIDs bridge

    main

    When implementing SAML 2.0, you have two primary architectural paths:

    Direct Integration (using ITfoxtec.Identity.Saml2.MvcCore)

    Use this approach when you want to implement SAML 2.0 protocols directly within your ASP.NET Core application code. This is suitable if your application needs to handle the SAML 2.0 logic itself.

    FoxIDs Bridge

    Use FoxIDs if your application already supports OpenID Connect or WS-Federation and you want to avoid adding another federation protocol implementation. FoxIDs acts as a bridge (e.g., SAML 2.0 to OpenID Connect), handling the SAML 2.0 connection externally.

    Choose FoxIDs if you need to:

    • Use a SAML 2.0 to OpenID Connect or WS-Federation bridge.
    • Integrate SAML 2.0 without changing an existing OIDC or WS-Federation application.
    • Move protocol translation, certificates, metadata, and partner-specific configuration outside of your application code.
    • Require architecture guidance for complex federation setups or SAML 2.0 migrations.
  6. Install ITfoxtec.Identity.Saml2.Mvc

    main

    To add ASP.NET MVC 5 integration helpers for SAML 2.0 to your project, install the ITfoxtec.Identity.Saml2.Mvc package via NuGet. This package provides the necessary plumbing for SAML 2.0 sign-on, logout, metadata, and binding handling within an MVC application. Note that this package depends on ITfoxtec.Identity.Saml2 for the core protocol implementation.

    Install-Package ITfoxtec.Identity.Saml2.Mvc
  7. Build and test the ITfoxtec.Identity.Saml2 solution

    main

    To build the project from source and run the included tests, use the following commands:

    Restore and Build:

    dotnet restore ITfoxtec.Identity.Saml2.sln
    dotnet build ITfoxtec.Identity.Saml2.sln -c Release

    Run Unit Tests:

    dotnet test UnitTest/ITfoxtec.Identity.Saml2.Tests/ITfoxtec.Identity.Saml2.Tests.csproj

    Run ASP.NET Core Sample:

    dotnet run --project test/TestWebAppCore/TestWebAppCore.csproj
    dotnet restore ITfoxtec.Identity.Saml2.sln
    dotnet build ITfoxtec.Identity.Saml2.sln -c Release
    dotnet test UnitTest/ITfoxtec.Identity.Saml2.Tests/ITfoxtec.Identity.Saml2.Tests.csproj
    dotnet run --project test/TestWebAppCore/TestWebAppCore.csproj
  8. Install ITfoxtec.Identity.Saml2 packages

    main

    Depending on your application type, install the appropriate package via NuGet:

    • Core SAML 2.0 implementation: Use ITfoxtec.Identity.Saml2 for direct integration in any .NET application.
    • ASP.NET Core MVC: Use ITfoxtec.Identity.Saml2.MvcCore for integration helpers.
    • ASP.NET MVC 5 (.NET Framework): Use ITfoxtec.Identity.Saml2.Mvc for integration helpers.
    # Core package
    dotnet add package ITfoxtec.Identity.Saml2
    
    # ASP.NET Core MVC integration
    dotnet add package ITfoxtec.Identity.Saml2.MvcCore
    
    # ASP.NET MVC 5 integration (PowerShell)
    Install-Package ITfoxtec.Identity.Saml2.Mvc
  9. Integrate SAML 2.0 with ASP.NET Core MVC

    main

    The ITfoxtec.Identity.Saml2.MvcCore package provides helpers to handle SAML 2.0 sign-on, logout, metadata, and binding within ASP.NET Core applications.

    Key integration features include:

    • Service Registration: Use AddSaml2 to register necessary services in the ASP.NET Core dependency injection container.
    • Middleware Registration: Use UseSaml2 to register the SAML 2.0 middleware in the request pipeline.
    • Request Conversion: Automatically converts ASP.NET Core requests into SAML 2.0 requests.
    • Response Helpers: Provides IActionResult helpers for handling Redirect, POST, Artifact, SOAP, and metadata responses.
    • Authentication Integration: Integrates with Cookie authentication for SAML 2.0 login and logout flows.