DEV Community

Paweł Ruciński
Paweł Ruciński

Posted on • Edited on

Adding Proxy-Authorization header in swagger

Hi all,
I already posted this question on stack overflow, but I think, that here I can find interested people faster.

I need to add specific header on swagger ui using .net core. Is there any way to include header like this?

Already tried:

  • implementing IOperationFilter:
public void Apply(Operation operation, OperationFilterContext context)
{
    if (operation.Parameters == null)
        operation.Parameters = new List<IParameter>();

    if (operation.Parameters.All(p => p.Name != "Proxy-Authorization"))
    {
        operation.Parameters.Add(new NonBodyParameter
        {
            Name = "Proxy-Authorization",
            In = "header",
            Description = "Proxy-Authorization token",
            Required = true,
            Type = "string"
        });
    }
}
Enter fullscreen mode Exit fullscreen mode
  • adding security definition:
options.AddSecurityDefinition("Authorization", new ApiKeyScheme()
{
    In = "header",
    Description = "Please insert Proxy Authorization Secret into field",
    Name = "Proxy-Authorization",
    Type = "apiKey"
});
Enter fullscreen mode Exit fullscreen mode

Both didn't work. When I change header name everything works fine (HttpContext.Request.Headers contains desirable header), but this specific ( Proxy-Authorization) header is wiped out from a call.

Did you ever meet this issue? How to solve it?

EDIT:

I confirmed that this is not the issue in .net core only. Full .net framework has also this bug.

Furthermore it is only affected on header with proxy- prefix.

Top comments (3)

Collapse
 
thutrangctp profile image
thutrangctp

I confirmed that this is not the issue in .net core only superfighters

Collapse
 
meanin profile image
Paweł Ruciński • Edited

If anyone is interested in this topic, please find my repository presenting this issue in full .net framework.

Collapse
 
deanmark092 profile image
Dean Mark

I always wonder what is proxy authorization
happy wheels