Skip to content
This repository has been archived by the owner on Jan 11, 2021. It is now read-only.

How to integrate swagger with JWT? #757

Open
JHaazez opened this issue May 22, 2018 · 5 comments
Open

How to integrate swagger with JWT? #757

JHaazez opened this issue May 22, 2018 · 5 comments

Comments

@JHaazez
Copy link

JHaazez commented May 22, 2018

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: #708.

@sang-d
Copy link

sang-d commented Jun 15, 2018

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

@brumasribera
Copy link

brumasribera commented Sep 24, 2018

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.

@wdschn
Copy link

wdschn commented Oct 30, 2018

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.

@JejeDurden
Copy link

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.

@zar777
Copy link

zar777 commented Dec 9, 2018

Thanks @JejeDurden it works perfectly fine!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants