< Summary

Information
Class: ProjectTemplate.Web.Authentication.Providers.OpenIdConnect.OpenIdConnectAuthenticationServiceExtensions
Assembly: ProjectTemplate.Web
File(s): /home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/src/ProjectTemplate.Web/Authentication/Providers/OpenIdConnect/OpenIdConnectAuthenticationServiceExtensions.cs
Line coverage
100%
Covered lines: 22
Uncovered lines: 0
Coverable lines: 22
Total lines: 49
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddOpenIdConnectAuthentication(...)100%44100%

File(s)

/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/src/ProjectTemplate.Web/Authentication/Providers/OpenIdConnect/OpenIdConnectAuthenticationServiceExtensions.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Authentication;
 2using Microsoft.AspNetCore.Authentication.Cookies;
 3
 4namespace ProjectTemplate.Web.Authentication.Providers.OpenIdConnect;
 5
 6/// <summary>
 7/// Provides extension methods for registering OpenID Connect authentication provider services.
 8/// </summary>
 9public static class OpenIdConnectAuthenticationServiceExtensions
 10{
 11    /// <summary>
 12    /// Adds the OpenID Connect authentication provider registration.
 13    /// </summary>
 14    /// <param name="builder">The authentication builder used to register authentication handlers.</param>
 15    /// <param name="options">The OpenID Connect provider options.</param>
 16    /// <returns>The same <see cref="AuthenticationBuilder"/> instance for chaining.</returns>
 17    public static AuthenticationBuilder AddOpenIdConnectAuthentication(
 18        this AuthenticationBuilder builder,
 19        OpenIdConnectAuthenticationOptions options)
 20    {
 18221        ArgumentNullException.ThrowIfNull(builder);
 18022        ArgumentNullException.ThrowIfNull(options);
 23
 17824        if (!options.Enabled)
 25        {
 17226            return builder;
 27        }
 28
 629        builder.AddOpenIdConnect(options.Scheme, options.DisplayName, openIdConnectOptions =>
 630        {
 231            openIdConnectOptions.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
 232            openIdConnectOptions.Authority = options.Authority;
 233            openIdConnectOptions.ClientId = options.ClientId;
 234            openIdConnectOptions.ClientSecret = options.ClientSecret;
 235            openIdConnectOptions.CallbackPath = options.CallbackPath;
 236            openIdConnectOptions.ResponseType = options.ResponseType;
 237            openIdConnectOptions.SaveTokens = options.SaveTokens;
 638
 239            openIdConnectOptions.Scope.Clear();
 640
 2441            foreach (string scope in options.Scopes.Where(scope => !string.IsNullOrWhiteSpace(scope)))
 642            {
 643                openIdConnectOptions.Scope.Add(scope);
 644            }
 845        });
 46
 647        return builder;
 48    }
 49}