I want to achieve the authorization button in Swagger. For the older version, there were some configurations for Swagger, but I guess those configurations are not needed in the newer version. Added a picture that I want to achieve. I know what Basic auth but my requirement is a header i.e authorization of the bearer and token. Thanks in advance for the help.
Asked
Active
Viewed 1,820 times
0
-
Check this link https://stackoverflow.com/questions/59357205/springdoc-openapi-apply-default-global-securityscheme-possible – Ret Ret Aug 25 '23 at 10:44
-
Check this link [https://stackoverflow.com/questions/59357205/springdoc-openapi-apply-default-global-securityscheme-possible](https://stackoverflow.com/questions/59357205/springdoc-openapi-apply-default-global-securityscheme-possible). – Ret Ret Aug 26 '23 at 01:27
2 Answers
2
Added
@SecurityScheme(
name = "bearerAuth",
scheme = "bearer",
bearerFormat = "JWT",
type = SecuritySchemeType.HTTP,
in = SecuritySchemeIn.HEADER
)
This configuration is in the main class.
Add @SecurityRequirement(name = "bearerAuth")
It is in the Controller class, or you can add it at your endpoints, which works for me.

Leonardo
- 1,263
- 7
- 20
- 51

Anil Singh
- 31
- 5
1
You probably have a @Configuration
class with OpenApi information.
There, you should configure your OpenAPI()
instance with the following:
new OpenAPI().
//... whatever configuration you have
.components(
new Components().addSecuritySchemes(
"api",
new SecurityScheme()
.scheme("bearer")
.type(SecurityScheme.Type.HTTP)
.bearerFormat("jwt") //if it is your case
.name("api")
)
)
Sorry I'm translating it from Kotlin, but you got the Java idea :)

Leonardo
- 1,263
- 7
- 20
- 51
-
Thank you for your comment, but no configuration is needed for the new spring boot version. I got the Solution in one line. – Anil Singh Mar 06 '23 at 16:01
-