< Summary

Information
Class: Chronicis.Client.Services.ChronicisAuthHandler
Assembly: Chronicis.Client
File(s): /home/runner/work/chronicis/chronicis/src/Chronicis.Client/Services/ChronicisAuthHandler.cs
Line coverage
100%
Covered lines: 3
Uncovered lines: 0
Coverable lines: 3
Total lines: 38
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%

File(s)

/home/runner/work/chronicis/chronicis/src/Chronicis.Client/Services/ChronicisAuthHandler.cs

#LineLine coverage
 1using System.Net.Http.Headers;
 2using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
 3
 4namespace Chronicis.Client.Services;
 5
 6/// <summary>
 7/// DelegatingHandler that automatically attaches the Auth0 bearer token to all outgoing requests.
 8/// Uses standard Authorization header now that API is hosted on separate App Service.
 9/// </summary>
 10public class ChronicisAuthHandler : DelegatingHandler
 11{
 12    private readonly IAccessTokenProvider _tokenProvider;
 13
 514    public ChronicisAuthHandler(IAccessTokenProvider tokenProvider)
 15    {
 516        _tokenProvider = tokenProvider;
 517    }
 18
 19    protected override async Task<HttpResponseMessage> SendAsync(
 20        HttpRequestMessage request,
 21        CancellationToken cancellationToken)
 22    {
 23        var tokenResult = await _tokenProvider.RequestAccessToken(
 24            new AccessTokenRequestOptions
 25            {
 26                Scopes = new[] { "openid", "profile", "email" }
 27            });
 28
 29        if (tokenResult.TryGetToken(out var token))
 30        {
 31            // Use standard Authorization header
 32            // Now that API is on separate App Service, Azure SWA no longer intercepts this
 33            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token.Value);
 34        }
 35
 36        return await base.SendAsync(request, cancellationToken);
 37    }
 38}