Skip to content

Instantly share code, notes, and snippets.

@TechWatching
Last active May 19, 2021 16:49
Show Gist options
  • Save TechWatching/54e992e0dcc6c30436902b8f7672e599 to your computer and use it in GitHub Desktop.
Save TechWatching/54e992e0dcc6c30436902b8f7672e599 to your computer and use it in GitHub Desktop.
public class UserApiAuthenticationHandler : DelegatingHandler
{
private readonly IUserApiAuthenticationService _authenticationService;
public UserApiAuthenticationHandler(IUserApiAuthenticationService authenticationService)
{
_authenticationService = authenticationService;
}
protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationTokencancellationToken)
{
var token = await _authenticationService.RetrieveToken();
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
return await base.SendAsync(request, cancellationToken);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment