Skip to content
Advertisement

Spring Boot, Swagger and Authorisation

I have a Spring Boot API that uses Springdoc (Swagger). The API has security with “apiKey” and “code” fields being passed in the header. I am having difficulty configuring Swagger correctly to enable the Authentication function in the Swagger UI. This is the configuration:

JavaScript

I know this is incorrect, but are unsure how to configure it.

Any assistance appreciated.

Attempts at solution: from @indybee recommendation:

JavaScript

This is where I get to (unfortunately, it still doesn’t authorize when I test an endpoint)

enter image description here

Finally, this appears to work (using guidance from @indybee):

addSecurityItem()

JavaScript

Advertisement

Answer

To pass 2 custom headers of “apiKey” and “code” with every request

add this method:

JavaScript

and replace your .components() block with following

JavaScript

Authorize dialog

curl command

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement