django-rest-swagger icon indicating copy to clipboard operation
django-rest-swagger copied to clipboard

How to integrate swagger with JWT?

Open JHaazez opened this issue 6 years ago • 5 comments

Is it possible to use django-rest-swagger with JSON web tokens?

I've perused the documentation and open issues and many people have examples using 'rest_framework.authentication.TokenAuthentication' in their DEFAULT_AUTHENTICATION_CLASSES but I have not seen any examples for 'rest_framework_jwt.authentication.JSONWebTokenAuthentication'.

Is this functionality part of the project or has this not been implemented yet?

For example this is what I am trying to achieve: REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework_jwt.authentication.JSONWebTokenAuthentication', ), }

SWAGGER_SETTINGS = { 'SECURITY_DEFINITIONS': { 'basic': {'type': 'apiKey'}, 'api_key': { 'type': 'apiKey', 'in': 'header', 'name': 'Authorization' } } }

Also, I do not see the Authorization parameter in my requests with the above method, which seems to be noted by another user commenting on this issue: https://github.com/marcgibbons/django-rest-swagger/issues/708.

JHaazez avatar May 22 '18 14:05 JHaazez

2.2.0 is having issue to include token in header. I have same above config, working for 2.1.2 but not 2.2.0

sang-d avatar Jun 15 '18 06:06 sang-d

Hello!

After the new version of OpenAPI it should now be possible to speficy JWT authentification like this:

{ "type": "http", "scheme": "bearer", "bearerFormat": "JWT", }

But if I do so I get a 'Unknown security definition type http' error.

I would be very grateful if you could add those changes so that Django REST Swagger is compliant to the new OpenAPI 3.0 spec.

brumasribera avatar Sep 24 '18 14:09 brumasribera

It is bad and I used django-rest-swagger==2.1.2. Can you show me your configuration? this is my versions: djangorestframework==3.6.4 djangorestframework-jwt==1.11.0 django-rest-swagger==2.1.2

Think you.

wdschn avatar Oct 30 '18 11:10 wdschn

Any update on this topic ?

For people looking for a solution, my currently working setup for djangorestframework-simplejwt : 1- Use django-rest-swagger==2.1.2 with:

'SECURITY_DEFINITIONS': {
        'api_key': {
            'type': 'apiKey',
            'in': 'header',
            'name': 'Authorization'
        }
    }

2- As a value after clicking on the Authorize button : 'Bearer yourAccessToken'

The UI is way better on the 2.2.0 so I can't wait for an update here.

JejeDurden avatar Nov 07 '18 18:11 JejeDurden

Thanks @JejeDurden it works perfectly fine!

zar777 avatar Dec 09 '18 03:12 zar777