'How to add Bearer {JWT} in swagger django?
when I authorize myself in Swagger UI, I have to write "Bearer {then I write JWT} here"
How can I add the string "Bearer" automatically before the JWT token in swagger UI? Here is my Swagger Settings:
SWAGGER_SETTINGS = {
"SECURITY_DEFINITIONS": {
"JWT [Bearer {JWT}]": {
"name": "Authorization",
"type": "apiKey",
"in": "header",
}
},
"USE_SESSION_AUTH": False,
}
FORCE_SCRIPT_NAME = "/"
Solution 1:[1]
I recommend you to migrate from drf-yasg
to drf_spectacular
, it already includes JWT authentication automatically and without so many complications, it even uses OpenAPI 3 (drf-yasg
uses OpenAPI 2 and is becoming obsolete)
Automatic Generation
Authenticate with JWT
See this From drf-yasg to OpenAPI 3
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Carlos Osuna |