-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
questionInitially seen a question could become a new feature or bug or closed ;)Initially seen a question could become a new feature or bug or closed ;)
Description
Hi
I need to change the access token of requests that go to the APIs via the Ocelot API Gateway.
I try to use a DelegatingHandler or PreQueryStringBuilderMiddleware/PreAuthorizationMiddleware, and the behaviour is the same.
Both change the Header in the request, but when I receive the request in the API, it seems that it uses all the original Headers. None of the new headers that I add reach the API.
Even tried to use it via configuration using the DownstreamHeaderTransform or UpstreamHeaderTransform in the route, but nothing.
Middleware
TokenResult tokenResult = ...;
DownstreamRequest downstreamRequest = httpContext.Items.DownstreamRequest();
httpContext.Request.Headers.Authorization = tokenResult.AccessToken;
// or
downstreamRequest.Headers.TryAddWithoutValidation("Authorization", $"Bearer {tokenResult.AccessToken}");
_logger.LogInformation($"New Token: {httpContext.Request.Headers.Authorization}");
Delegating handler
TokenResult tokenResult = ...;
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", tokenResult.AccessToken);
Is there some configuration that I'm missing to enable the injection of Headers?
Specifications
Version: 24.0.1
Platform: .NET 8
Subsystem: Windows
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
questionInitially seen a question could become a new feature or bug or closed ;)Initially seen a question could become a new feature or bug or closed ;)