< Summary

Information
Class: ProjectTemplate.Web.Authentication.Providers.Saml2.Saml2AuthenticationServiceExtensions
Assembly: ProjectTemplate.Web
File(s): /home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/src/ProjectTemplate.Web/Authentication/Providers/Saml2/Saml2AuthenticationServiceExtensions.cs
Line coverage
100%
Covered lines: 24
Uncovered lines: 0
Coverable lines: 24
Total lines: 55
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddSaml2Authentication(...)100%22100%

File(s)

/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/src/ProjectTemplate.Web/Authentication/Providers/Saml2/Saml2AuthenticationServiceExtensions.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Authentication;
 2using Microsoft.AspNetCore.Authentication.Cookies;
 3using Sustainsys.Saml2;
 4using Sustainsys.Saml2.Metadata;
 5
 6namespace ProjectTemplate.Web.Authentication.Providers.Saml2;
 7
 8/// <summary>
 9/// Provides extension methods for registering SAML2 authentication provider services.
 10/// </summary>
 11public static class Saml2AuthenticationServiceExtensions
 12{
 13    /// <summary>
 14    /// Adds SAML2 authentication using the specified options to the authentication builder.
 15    /// </summary>
 16    /// <remarks>If the SAML2 authentication is not enabled in the provided options, the method returns the
 17    /// original builder without modification.</remarks>
 18    /// <param name="builder">The authentication builder to which the SAML2 authentication scheme is added.</param>
 19    /// <param name="options">The options used to configure the SAML2 authentication scheme. Cannot be null.</param>
 20    /// <returns>The authentication builder with the SAML2 authentication scheme configured.</returns>
 21    public static AuthenticationBuilder AddSaml2Authentication(
 22        this AuthenticationBuilder builder,
 23        Saml2AuthenticationOptions options)
 24    {
 18225        ArgumentNullException.ThrowIfNull(builder);
 18026        ArgumentNullException.ThrowIfNull(options);
 27
 17828        if (!options.Enabled)
 29        {
 17230            return builder;
 31        }
 32
 633        builder.AddSaml2(options.Scheme, options.DisplayName, saml2Options =>
 634        {
 235            saml2Options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
 236            saml2Options.SPOptions.EntityId = new EntityId(options.EntityId);
 237            saml2Options.SPOptions.ModulePath = options.ModulePath;
 238            saml2Options.SPOptions.WantAssertionsSigned = options.RequireSignedAssertions;
 239            saml2Options.SPOptions.ValidateCertificates = options.ValidateCertificates;
 640
 241            IdentityProvider identityProvider = new(
 242                new EntityId(options.MetadataUrl),
 243                saml2Options.SPOptions)
 244            {
 245                MetadataLocation = options.MetadataUrl,
 246                LoadMetadata = options.LoadMetadata,
 247                AllowUnsolicitedAuthnResponse = false
 248            };
 649
 250            saml2Options.IdentityProviders.Add(identityProvider);
 851        });
 52
 653        return builder;
 54    }
 55}