in Application/UI/Blazor/ImageRecognition/ServiceClientFactory.cs [61:83]
private async Task<HttpClient> ConstructHttpClient()
{
var authState = await _authenticationStateProvider.GetAuthenticationStateAsync();
var user = authState.User;
if (!user.Identity.IsAuthenticated)
throw new Exception();
var userId = _cognitoUserManager.GetUserId(user);
if (string.IsNullOrEmpty(userId))
throw new Exception();
var cognitoUser = await _cognitoUserManager.FindByIdAsync(userId);
if (string.IsNullOrEmpty(cognitoUser?.SessionTokens.IdToken))
throw new Exception();
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization =
AuthenticationHeaderValue.Parse($"bearer {cognitoUser.SessionTokens.IdToken}");
return httpClient;
}