-
Notifications
You must be signed in to change notification settings - Fork 271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Customize bearer token in authorization header #467
Comments
Hi, so we do use the
Do you use a custom version of |
Thanks for your quick response. |
this is indeed a bug. same thing was fixed for DRF's TokenAuthentication but it was forgotten here. however, the solution to this is not perfect. OpenAPI3 does not directly support customizing "Bearer". When you use non-"Bearer", you will need to put the whole shabang into SwaggerUI, i.e. preparing a fix right now. |
Thanks alot. |
@tombra4ril yes that was the problem. with this commit "Bearer" is not prefixed anymore, iff it is some other value like "JWT". |
closing this issue for now. feel free to comment if anything is missing or not working and we will follow-up. |
@tfranzel sorry for the delay. Was able to install this fix commit and the authorization bug has been fixed, thanks a lot. |
Hi there, First of great library! We are using FireBase for our authentication ( In turn we tried to use the bearerFormat as denoted here. Example:
Actual response: Expected response: The only way I was able to make it functional was in the following way:
However it seems that this is not ideal and more of a workaround. I see the ticket is closed, but not sure how I can specify the bearerFormat correctly for JWT using FireBase auth. Thanks in advance. |
Hi @SidneyNiccolson, so the documentation suggests this and SwaggerUI actually implements it like that. afaik there is no way to specify a hard-coded prefix in OpenAPI 3.0.3 other than you can try this yourself with https://editor.swagger.io/. the last time i tried fiddling around with |
hello, |
@deepakkumhar it depends on which lib you are using: from drf_spectacular.contrib.rest_framework_simplejwt import SimpleJWTScheme
class CustomSimpleJWTScheme(SimpleJWTScheme):
name = 'breareauth'
priority = 1 or from drf_spectacular.contrib.rest_framework_jwt import JWTScheme
class CustomJWTScheme(JWTScheme):
name = 'breareauth'
priority = 1 |
thank you 👍 |
@tfranzel |
how can i remove or hide auto generate schema in drf_spectacular like my enum field generating separate schema so i want to remove it. |
Hi,
I am using simplejwt for authentication. To authorize users for a particular endpoint the authorization header should contain the bearer token (JWT) followed by the access token but spectacular uses bearer as the default even after specifying
"AUTH_HEADER_TYPES": ("JWT",)
in simple_jwt configuration in mysettings.py
file.Headers sent
curl -X POST "http://localhost:8000/api/v1/auth/test" -H "accept: /" -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjI3Mjc0MTYzLCJqdGkiOiIwMjU2NjAyOWViZDg0NDk4OWU2Y2QyMTgwNzc0YTczZ..." -H "X-CSRFToken: lioQLVfM4CLuI2cSVXE1MtXRBeAHYHH6FnlmUGqkKpnqd2PmNFQ9Yrop323tOu6q" -d ""
Expected headers
curl -X POST "http://localhost:8000/api/v1/auth/test" -H "accept: /" -H "Authorization: JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjI3Mjc0MTYzLCJqdGkiOiIwMjU2NjAyOWViZDg0NDk4OWU2Y2QyMTgwNzc0YTczZ..." -H "X-CSRFToken: lioQLVfM4CLuI2cSVXE1MtXRBeAHYHH6FnlmUGqkKpnqd2PmNFQ9Yrop323tOu6q" -d ""
Thanks for your response in advance.
The text was updated successfully, but these errors were encountered: