< 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
0%
Covered lines: 0
Uncovered lines: 12
Coverable lines: 12
Total lines: 38
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
SendAsync()0%620%

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
 014    public ChronicisAuthHandler(IAccessTokenProvider tokenProvider)
 15    {
 016        _tokenProvider = tokenProvider;
 017    }
 18
 19    protected override async Task<HttpResponseMessage> SendAsync(
 20        HttpRequestMessage request,
 21        CancellationToken cancellationToken)
 22    {
 023        var tokenResult = await _tokenProvider.RequestAccessToken(
 024            new AccessTokenRequestOptions
 025            {
 026                Scopes = new[] { "openid", "profile", "email" }
 027            });
 28
 029        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
 033            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token.Value);
 34        }
 35
 036        return await base.SendAsync(request, cancellationToken);
 037    }
 38}