• +45 4949 9091
  • Support
  • Sprog
    • Sprog
    • English
    • Dansk
    • Svenska
    • Norsk
    • Deutsch
    • Nederlands
    • Polski
    • Français
    • Español
    • Italiano
    • Português
  • Tilmeld
  • Log ind
FoxIDs logo
  • Docs & værktøjer
    • Dokumentation
    • Artikler
    • JWT-værktøj
    • SAML 2.0 værktøj
    • Certifikatværktøj
  • Anvendelser
    • Oversigt
    • Kunder
    • Medarbejdere
    • Partnere
    • Kundehistorier
  • Tjenester
  • Platform
    • Deployering
    • Multi-tenant
    • Identitetslogik
    • Compliance
  • Priser
  • Tilmeld
  • Log ind

ITfoxtec Identity SAML 2.0

Den open source ITfoxtec Identity Saml2-pakke tilføjer SAML 2.0 / SAML-P-understøttelse til .NET-applikationer, der skal fungere som Identity Provider (IdP), Service Provider (SP) eller Relying Party (RP).

ITfoxtec Identity Saml2 er nyttig, når SAML 2.0 skal implementeres direkte i applikationen. Pakken understøtter SAML 2.0 login, logout, single logout, metadata, Redirect Binding, POST Binding, Artifact Binding, signering og validering af meddelelser, ECDSA-signaturer på understøttede moderne mål for .NET samt konfigurerbar kryptering og dekryptering af assertions.

Virksomhedsnavnet ITfoxtec er ændret til FoxIDs, men komponenterne vil foreløbigt beholde ITfoxtec navnet som en del af komponentnavnet.

Support

Stil spørgsmål på Stack Overflow og tag med 'itfoxtec-identity-saml2'.

For implementeringshjælp eller arkitekturrådgivning, skriv til contact@foxids.com.

Pakke

Udgivelser NuGet ITfoxtec Identity SAML 2.0 NuGet ITfoxtec Identity SAML 2.0 MVC NuGet ITfoxtec Identity SAML 2.0 MVC Core

Kode og licens

Kode på GitHub Testeksempler på GitHub Open source licens

Når FoxIDs er relevant

Der er to praktiske veje. Brug open source-biblioteket, når SAML 2.0 skal implementeres direkte i din .NET-applikation. Hvis applikationen allerede understøtter OpenID Connect eller WS-Federation, kan FoxIDs håndtere SAML 2.0-integrationen eksternt, mens applikationen fortsætter med at bruge sin eksisterende protokol.

  • Behold applikationer på OpenID Connect eller WS-Federation, mens FoxIDs håndterer SAML 2.0-forbindelsen
  • Kør protokoloversættelse, certifikater, metadata og partnerspecifik federationskonfiguration uden for applikationen
  • Brug FoxIDs Cloud, self-hosted eller hybrid deployment afhængigt af driftskrav
  • FoxIDs bruger ITfoxtec.Identity.Saml2 til SAML 2.0-protokolhåndtering, så biblioteket og bridge-muligheden er teknisk afstemt
SAML 2.0 bridge-dokumentation Tal med en ekspert Kom gratis i gang

Testede miljøer

ITfoxtec Identity Saml2 pakken er testet for overensstemmelse med Microsoft Entra ID (Azure AD), AD FS, Azure AD B2C, den danske NemLog-in3 (MitID), den danske Context Handler (på dansk kaldet Fælleskommunal Adgangsstyring) og mange andre IdP'er og RP'er.

ASP.NET MVC og ASP.NET Core MVC understøttes af ITfoxtec Identity SAML 2.0 MVC- og MVC Core-pakkerne, som hjælper med at integrere ITfoxtec SAML 2.0-pakken i MVC- og ASP.NET Core MVC-applikationer.

Understøttede .NET versioner

.NET 10.0 .NET 9.0 .NET 8.0 .NET 7.0 .NET 6.0 .NET Standard 2.1 .NET Framework 4.6.2 .NET Framework 4.8

Understøttede bindings

  • Redirect Binding
  • Post Binding
  • Artifact Binding

Bindings kan bruges efter behov til:

  • Authn Request
  • Authn Response (SAML 2.0 Response)
  • Logout Request
  • Logout Response

Signeringsalgoritmer

RSA SHA1/SHA256/SHA384/SHA512, RSA-PSS SHA256 og ECDSA SHA256/SHA384/SHA512 understøttes til meddelelsessignering og validering. ECDSA-understøttelse gælder for understøttede moderne .NET targets.

RSA SHA1 RSA SHA256 RSA SHA384 RSA SHA512 RSA-PSS SHA256 ECDSA SHA256 ECDSA SHA384 ECDSA SHA512
Vis algoritme-URI'er
  • RSA SHA1http://www.w3.org/2000/09/xmldsig#rsa-sha1
  • RSA SHA256http://www.w3.org/2001/04/xmldsig-more#rsa-sha256
  • RSA SHA384http://www.w3.org/2001/04/xmldsig-more#rsa-sha384
  • RSA SHA512http://www.w3.org/2001/04/xmldsig-more#rsa-sha512
  • RSA-PSS SHA256http://www.w3.org/2007/05/xmldsig-more#sha256-rsa-MGF1
  • ECDSA SHA256http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256
  • ECDSA SHA384http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha384
  • ECDSA SHA512http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha512

Konfigurerbar kryptering

Assertion-kryptering kan konfigureres separat for datakryptering og nøglekryptering. Understøttede muligheder omfatter AES-CBC, AES-GCM, RSA key transport og XML Encryption 1.1 RSA-OAEP med validerede MGF-parametre.

Data
AES-CBC AES-GCM
Key
RSA 1.5 RSA-OAEP RSA-OAEP 1.1

Du kan bruge SAML 2.0 værktøjet til at afkode tokens og oprette selvsignerede certifikater med certifikatværktøjet.

Kode

Koden, der vises, er kun et udvalg af eksempel koden på GitHub.

ITfoxtec Identity Saml2-pakken integreres i en ASP.NET Core MVC Relying Party (RP)-applikation ved konfiguration i Startup og ved at tilføje en Auth Controller med følgende metoder. Den viste binding kan ændres efter behov afhængigt af kravene.

Det er desuden muligt at sætte nogle valgfrie parametre på Saml2AuthnRequest og Saml2LogoutRequest. På Saml2AuthnRequest understøttes f.eks. ForceAuthn, som vil tvinge brugeren til at indtaste login oplysninger, selv om der allerede findes en SSO kontekst på Security Token Service (STS) / Identity Provider (IdP).


Tilføj konfiguration til ConfigureServices metoden i Startup

Konfiguration med IdP metadata.
services.BindConfig<Saml2Configuration>(Configuration, "Saml2", (serviceProvider, saml2Configuration) =>
{
    saml2Configuration.SigningCertificate = CertificateUtil.Load(AppEnvironment.MapToPhysicalFilePath(
        Configuration["Saml2:SigningCertificateFile"]), Configuration["Saml2:SigningCertificatePassword"]);
    saml2Configuration.AllowedAudienceUris.Add(saml2Configuration.Issuer);

    var httpClientFactory = serviceProvider.GetService<IHttpClientFactory>();
    var entityDescriptor = new EntityDescriptor();
    entityDescriptor.ReadIdPSsoDescriptorFromUrlAsync(httpClientFactory, new Uri(Configuration["Saml2:IdPMetadata"])).GetAwaiter().GetResult();
    if (entityDescriptor.IdPSsoDescriptor != null)
    {
        saml2Configuration.AllowedIssuer = entityDescriptor.EntityId;
        saml2Configuration.SingleSignOnDestination = entityDescriptor.IdPSsoDescriptor.SingleSignOnServices.First().Location;
        saml2Configuration.SingleLogoutDestination = entityDescriptor.IdPSsoDescriptor.SingleLogoutServices.First().Location;
        saml2Configuration.SignatureValidationCertificates.AddRange(entityDescriptor.IdPSsoDescriptor.SigningCertificates);
    }
    else
    {
        throw new Exception("IdPSsoDescriptor not loaded from metadata.");
    }
    return saml2Configuration;
});
services.AddSaml2();
services.AddHttpClient();

Konfiguration uden metadata.
services.BindConfig<Saml2Configuration>(Configuration, "Saml2", (serviceProvider, saml2Configuration) =>
{
    saml2Configuration.SigningCertificate = CertificateUtil.Load(AppEnvironment.MapToPhysicalFilePath(
        Configuration["Saml2:SigningCertificateFile"]), Configuration["Saml2:SigningCertificatePassword"]);
    saml2Configuration.AllowedAudienceUris.Add(saml2Configuration.Issuer);

    saml2Configuration.SignatureValidationCertificates.Add(CertificateUtil.Load(AppEnvironment.MapToPhysicalFilePath(
        Configuration["Saml2:SignatureValidationCertificateFile"])));
    return saml2Configuration;
});
services.AddSaml2();   

Login metode i Auth Controller

[Route("Login")]
public IActionResult Login(string returnUrl = null)
{
    var binding = new Saml2RedirectBinding();
    binding.SetRelayStateQuery(new Dictionary<string, string> 
        { { relayStateReturnUrl, returnUrl ?? Url.Content("~/") } });

    return binding.Bind(new Saml2AuthnRequest(config)).ToActionResult();
}

AssertionConsumerService metode i Auth Controller

Efter et vellykket eller mislykket login modtager ACS-metoden svaret.
[Route("AssertionConsumerService")]
public async Task<IActionResult> AssertionConsumerService()
{       
    var httpRequest = Request.ToGenericHttpRequest(validate: true);
    var saml2AuthnResponse = new Saml2AuthnResponse(config);

    httpRequest.Binding.ReadSamlResponse(httpRequest, saml2AuthnResponse);
    if (saml2AuthnResponse.Status != Saml2StatusCodes.Success)
    {
        throw new AuthenticationException($"SAML Response status: {saml2AuthnResponse.Status}");
    }
    httpRequest.Binding.Unbind(httpRequest, saml2AuthnResponse);
    await saml2AuthnResponse.CreateSessionAsync(HttpContext,
        claimsTransform: (claimsPrincipal) => Task.FromResult(ClaimsTransform.Transform(claimsPrincipal)));

    var relayStateQuery = httpRequest.Binding.GetRelayStateQuery();
    var returnUrl = relayStateQuery.ContainsKey(relayStateReturnUrl) ? relayStateQuery[relayStateReturnUrl] : Url.Content("~/");
    return Redirect(returnUrl);
}

Logout metode i Auth Controller

[HttpPost("Logout")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Logout()
{
    if (!User.Identity.IsAuthenticated)
    {
        return Redirect(Url.Content("~/"));
    }

    var binding = new Saml2PostBinding();
    var saml2LogoutRequest = await new Saml2LogoutRequest(config, User).DeleteSession(HttpContext);
    return binding.Bind(saml2LogoutRequest).ToActionResult();
}

LoggedOut metode i Auth Controller

Efter et vellykket eller mislykket logout modtager LoggedOut-metoden svaret.
[Route("LoggedOut")]
public IActionResult LoggedOut()
{
    var httpRequest = Request.ToGenericHttpRequest(validate: true);
    httpRequest.Binding.Unbind(httpRequest, new Saml2LogoutResponse(config));

    return Redirect(Url.Content("~/"));
}

SingleLogout metode i Auth Controller

Modtager en anmodning om Single Logout og sender et svar.
[Route("SingleLogout")]
public async Task<IActionResult> SingleLogout()
{
    Saml2StatusCodes status;
    var httpRequest = Request.ToGenericHttpRequest(validate: true);
    var logoutRequest = new Saml2LogoutRequest(config, User);
    try
    {
        httpRequest.Binding.Unbind(httpRequest, logoutRequest);
        status = Saml2StatusCodes.Success;
        await logoutRequest.DeleteSession(HttpContext);
    }
    catch (Exception exc)
    {
        // log exception
        Debug.WriteLine("SingleLogout error: " + exc.ToString());
        status = Saml2StatusCodes.RequestDenied;
    }

    var responseBinding = new Saml2PostBinding();
    responseBinding.RelayState = httpRequest.Binding.RelayState;
    var saml2LogoutResponse = new Saml2LogoutResponse(config)
    {
        InResponseToAsString = logoutRequest.IdAsString,
        Status = status,
    };
    return responseBinding.Bind(saml2LogoutResponse).ToActionResult();
}
FoxIDs logo

Udviklet i Danmark. Hostet i Europa.

Udviklere

  • Dokumentation
  • Artikler
  • Udgivelser
  • Cloud-status

Produkt

  • Priser
  • Tjenester
  • Deployering
  • Compliance
  • Tillidscenter

Virksomhed

  • Om
  • SKI-leverandør
  • Kontakt os

Juridisk

  • Brugsbetingelser
  • Vilkår for selvhosting
  • GDPR og databeskyttelsesaftale
  • Privatlivs- og cookiepolitik
© 2026 FoxIDs, version 2.15.13
GitHub LinkedIn

Valg af cookies

FoxIDs bruger nødvendige cookies for at få hjemmesiden til at fungere. Vælg Acceptér alle for også at tillade statistikcookies, som hjælper os med at forstå og forbedre hjemmesiden, eller Afvis alle for kun at bruge nødvendige cookies. Du kan til enhver tid ændre dit valg i vores privatlivs- og cookiepolitik.

Læs privatlivs- og cookiepolitikken