< Summary

Information
Class: ProjectTemplate.Web.Authentication.Providers.Google.GoogleAuthenticationServiceExtensions
Assembly: ProjectTemplate.Web
File(s): /home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/src/ProjectTemplate.Web/Authentication/Providers/Google/GoogleAuthenticationServiceExtensions.cs
Line coverage
100%
Covered lines: 20
Uncovered lines: 0
Coverable lines: 20
Total lines: 48
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddGoogleAuthentication(...)100%66100%

File(s)

/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/src/ProjectTemplate.Web/Authentication/Providers/Google/GoogleAuthenticationServiceExtensions.cs

#LineLine coverage
 1using Microsoft.AspNetCore.Authentication;
 2using Microsoft.AspNetCore.Authentication.Cookies;
 3using ProjectTemplate.Web.Authentication.Options;
 4
 5namespace ProjectTemplate.Web.Authentication.Providers.Google;
 6
 7/// <summary>
 8/// Provides extension methods for registering Google authentication provider services.
 9/// </summary>
 10public static class GoogleAuthenticationServiceExtensions
 11{
 12    /// <summary>
 13    /// Adds the Google authentication provider registration.
 14    /// </summary>
 15    /// <param name="builder">The authentication builder used to register authentication handlers.</param>
 16    /// <param name="options">The Google provider options.</param>
 17    /// <returns>The same <see cref="AuthenticationBuilder"/> instance for chaining.</returns>
 18    public static AuthenticationBuilder AddGoogleAuthentication(
 19        this AuthenticationBuilder builder,
 20        ApplicationExternalAuthenticationProviderOptions options)
 21    {
 18622        ArgumentNullException.ThrowIfNull(builder);
 18423        ArgumentNullException.ThrowIfNull(options);
 24
 18225        if (!options.Enabled)
 26        {
 17427            return builder;
 28        }
 29
 830        builder.AddGoogle(options.Scheme, options.DisplayName, googleOptions =>
 831        {
 232            googleOptions.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
 233            googleOptions.ClientId = options.ClientId;
 234            googleOptions.ClientSecret = options.ClientSecret;
 235            googleOptions.CallbackPath = options.CallbackPath;
 836
 2437            foreach (string scope in options.Scopes.Where(scope => !string.IsNullOrWhiteSpace(scope)))
 838            {
 639                if (!googleOptions.Scope.Contains(scope, StringComparer.Ordinal))
 840                {
 241                    googleOptions.Scope.Add(scope);
 842                }
 843            }
 1044        });
 45
 846        return builder;
 47    }
 48}