Clean up the auth delegating handler
This commit is contained in:
		
							parent
							
								
									af42aab95e
								
							
						
					
					
						commit
						184ed15ef6
					
				| @ -102,7 +102,10 @@ internal static class Extensions | ||||
|             // Set the access token as a bearer token for the outgoing request | ||||
|             var accessToken = await httpContext.GetTokenAsync("access_token"); | ||||
| 
 | ||||
|             if (accessToken is not null) | ||||
|             { | ||||
|                 proxyRequest.Headers.Authorization = new("Bearer", accessToken); | ||||
|             } | ||||
| 
 | ||||
|             await base.TransformRequestAsync(httpContext, proxyRequest, destinationPrefix, cancellationToken); | ||||
|         } | ||||
|  | ||||
| @ -12,29 +12,13 @@ public class HttpClientAuthorizationDelegatingHandler | ||||
| 
 | ||||
|     protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||||
|     { | ||||
|         var authorizationHeader = _httpContextAccessor.HttpContext | ||||
|             .Request.Headers["Authorization"]; | ||||
|         var accessToken = await _httpContextAccessor.HttpContext.GetTokenAsync("access_token"); | ||||
| 
 | ||||
|         if (!string.IsNullOrEmpty(authorizationHeader)) | ||||
|         if (accessToken is not null) | ||||
|         { | ||||
|             request.Headers.Add("Authorization", new List<string>() { authorizationHeader }); | ||||
|         } | ||||
| 
 | ||||
|         var token = await GetToken(); | ||||
| 
 | ||||
|         if (token != null) | ||||
|         { | ||||
|             request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); | ||||
|             request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); | ||||
|         } | ||||
| 
 | ||||
|         return await base.SendAsync(request, cancellationToken); | ||||
|     } | ||||
| 
 | ||||
|     async Task<string> GetToken() | ||||
|     { | ||||
|         const string ACCESS_TOKEN = "access_token"; | ||||
| 
 | ||||
|         return await _httpContextAccessor.HttpContext | ||||
|             .GetTokenAsync(ACCESS_TOKEN); | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user