1

We are using Swagger-Net with Bearer Token Authorization as follows:

c.ApiKey("Authorization", "header", "Bearer Token Authentication");

The request needs to be sent in the format "Bearer [bearertoken]", and I have verified this does work correctly when pasted in this format into the "API Key" authorization textbox. The Curl shows it being passed in the header as -H "Authorization: Bearer [token] and the API request succeeds.

Is there any way to automatically send a known token along with every API request? Or asked another way, is there any way to pre-fill this dynamically created API Key textbox with a known string to simplify the process for the end using testing our API?

Patrick
  • 5,526
  • 14
  • 64
  • 101
  • In Swagger UI you do this by using [`requestInterceptor`](https://stackoverflow.com/a/45471010/113116). Maybe Swagger-Net has a config for that. – Helen Jun 08 '20 at 14:17
  • @Helen Thanks, does this approach require swapping out index.html with a fully custom version? I know I can inject JavaScript with Swagger-Net. – Patrick Jun 08 '20 at 14:24
  • No idea, I haven't used Swagger-Net myself. – Helen Jun 08 '20 at 14:27
  • You could inject the custom javascript and UI and add a section to populate the Authorization header textbox on all APIs – Paresh Jun 08 '20 at 16:43

0 Answers0