< 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: 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
AddGoogleAuthentication(...)100%22100%

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    {
 13422        ArgumentNullException.ThrowIfNull(builder);
 13323        ArgumentNullException.ThrowIfNull(options);
 24
 13225        if (!options.Enabled)
 26        {
 12827            return builder;
 28        }
 29
 430        builder.AddGoogle(options.Scheme, options.DisplayName, googleOptions =>
 431        {
 432            googleOptions.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
 433            googleOptions.ClientId = options.ClientId;
 434            googleOptions.ClientSecret = options.ClientSecret;
 435            googleOptions.CallbackPath = options.CallbackPath;
 436
 437            foreach (string scope in options.Scopes.Where(scope => !string.IsNullOrWhiteSpace(scope)))
 438            {
 439                if (!googleOptions.Scope.Contains(scope, StringComparer.Ordinal))
 440                {
 441                    googleOptions.Scope.Add(scope);
 442                }
 443            }
 444        });
 45
 446        return builder;
 47    }
 48}