question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request header not sent (custom "Authorization" header) for Try It requests

See original GitHub issue

Q&A (please complete the following information)

  • OS: Windows 10
  • Browser: Firefox (also Chrome)
  • Version: 69.0.2
  • Method of installation: npm (via Swashbuckle)
  • Swagger-UI version: 3.23.8
  • Swagger/OpenAPI version: OpenAPI 3.0.1

Content & configuration

Example Swagger/OpenAPI definition: Full JSON @ https://gist.github.com/kierenj/a2f30015ddfb756f86c2b5e93c3401a8 Single example endpoint @ https://gist.github.com/kierenj/73e001386efe7d39a5d87fc1dbfa109a

Swagger-UI configuration options:

SwaggerUI({
  // I'm using Swashbuckle (the .NET wrapper), so I don't have equivalent JSON, sorry.
  // however, I only use the default options with it:
  /*
            swaggerUiOptions.RoutePrefix = "swagger";
            swaggerUiOptions.SwaggerEndpoint("/api/swagger.json", "API");
  */
})

Describe the bug you’re encountering

For a long time, I’ve been able to specify a value for this header with this method. However now, I enter a value, click Execute, and the header is not sent. The example curl request shown does not include the header, either. It’s not shown in the Network tab either.

To reproduce…

  1. Open Swagger UI with the JSON definition I shared
  2. Open /system/info
  3. Click Try it out
  4. Enter a value (e.g. Bearer X) in the header box
  5. Click Execute

Expected behavior

Authorization header is included in request.

Additional context or thoughts

I realise there are other ways of doing authorization with Swagger UI. They don’t quite meet my needs and so I’d hope to be able to continue using this method. Since this has been persistently working for a very long time (several years) I presume this is a bug.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
hkosovacommented, Oct 4, 2019

Your API definition is missing the securitySchemes and security keywords that are used to define authentication.

The Authorization header parameter defined in /auth/credentials and /system/info won’t be used because OpenAPI Specification says that tools should ignore explicit header parameters named Authorization. The Authorization header should be defined as a security scheme instead.

You need to change your Swashbuckle configuration so that it includes proper securitySchemes and security definitions in the generated JSON file. Please check Swashbuckle documentation or open a ticket with them for support.

0reactions
webroncommented, Oct 17, 2019

@kierenj I’m closing the ticket for now, because as it is, this is not something we’re going to support (when the spec specifically disallows it). If you encounter further issues, feel free to add a comment or open a new ticket.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Request headers are not getting sent - Help - Postman
I set a custom header, but it is not getting sent. This has worked in the past, but I cannot recall exactly when....
Read more >
Spring Boot Custom Authorization Header request not going ...
I'm trying to get authorization to work but am running into issues. Spring is able to login the user and return a token...
Read more >
Authorization - HTTP - MDN Web Docs - Mozilla
The HTTP Authorization request header can be used to provide credentials that authenticate a user agent with a server, allowing access to a ......
Read more >
How do I send GET Request with Custom Headers? - ReqBin
To send a GET request with custom HTTP headers, you must provide custom headers in the "Name: Value" format, just like the standard...
Read more >
Request and response behavior for custom origins
CloudFront forwards the Authorization header field to your origin if you do not configure CloudFront to cache responses to OPTIONS requests.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found