< Summary

Information
Class: ArturRios.Util.WebApi.Security.Authentication.GoogleTokenVerifier
Assembly: ArturRios.Util.WebApi
File(s): /home/ci/agent/workspace/dotnet-webapi-util-docs_main/app/src/Security/Authentication/GoogleTokenVerifier.cs
Line coverage
88%
Covered lines: 8
Uncovered lines: 1
Coverable lines: 9
Total lines: 35
Line coverage: 88.8%
Branch coverage
33%
Covered branches: 2
Total branches: 6
Branch coverage: 33.3%
Method coverage
100%
Covered methods: 1
Fully covered methods: 0
Total methods: 1
Method coverage: 100%
Full method coverage: 0%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
VerifyAsync()33.33%6688.88%

File(s)

/home/ci/agent/workspace/dotnet-webapi-util-docs_main/app/src/Security/Authentication/GoogleTokenVerifier.cs

#LineLine coverage
 1using ArturRios.Util.WebApi.Security.Interfaces;
 2using ArturRios.Util.WebApi.Security.Records;
 3using Google.Apis.Auth;
 4
 5namespace ArturRios.Util.WebApi.Security.Authentication;
 6
 7/// <summary>Default <see cref="IGoogleTokenVerifier"/> backed by <see cref="GoogleJsonWebSignature"/>, which fetches an
 8public class GoogleTokenVerifier : IGoogleTokenVerifier
 9{
 10    /// <inheritdoc />
 11    public async Task<GoogleTokenPayload?> VerifyAsync(string token, IEnumerable<string> audiences)
 12    {
 713        if (string.IsNullOrWhiteSpace(token))
 14        {
 215            return null;
 16        }
 17
 18        try
 19        {
 520            var settings = new GoogleJsonWebSignature.ValidationSettings { Audience = audiences };
 521            var payload = await GoogleJsonWebSignature.ValidateAsync(token, settings);
 22
 023            return new GoogleTokenPayload(payload.Email ?? string.Empty, payload.Subject ?? string.Empty, payload.EmailV
 24        }
 25        // A token that is not a well-formed JWS at all - bad base64url, a segment that is not JSON - makes
 26        // GoogleJsonWebSignature throw the decoder's own exception instead of InvalidJwtException. Any such
 27        // token is just not a valid Google token, so it is a 401, not a 500. Failures fetching Google's keys
 28        // (HttpRequestException) still propagate: those are the server's problem, not the caller's.
 529        catch (Exception exception) when (exception is InvalidJwtException or FormatException or ArgumentException
 530                                              or Newtonsoft.Json.JsonException)
 31        {
 532            return null;
 33        }
 734    }
 35}

Methods/Properties

VerifyAsync()