0

When i login using my api in the swagger and fill in the information in the Authorize button pop up, my api list which is protected still does not appear.

I tried adding it as 'Bearer token', but it do not work.

Following is my code:

SWAGGER_SETTINGS = {
 'LOGIN_URL': 'api:login',
 'LOGOUT_URL': 'api:logout',
 'USE_SESSION_AUTH': False,
 'DOC_EXPANSION': 'list',
 'APIS_SORTER': 'alpha',
 'SECURITY_DEFINITIONS': {
     'api_key': {
         'type': 'apiKey',
         'in': 'header',
         'name': 'Authorization',
         "description": "JWT authorization"
     }
 },
}


'DEFAULT_AUTHENTICATION_CLASSES': [
    'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
],

# Permission settings
'DEFAULT_PERMISSION_CLASSES': [
    'rest_framework.permissions.IsAuthenticated',
],

I am using django-rest-swagger==2.2.0. It works in swagger 2.1.2

Sandhu
  • 348
  • 5
  • 23

2 Answers2

1

in your root urls.py s


schema_view = get_schema_view(
openapi.Info(
  x,
  y,
  z,
  ),
public=True,
permission_classes=(permissions.AllowAny,),
)

you should check if it has permission_classes set to AllowAny! or you just forget to add them!

p.s. It's too late but maybe helps others!

RTK
  • 17
  • 7
0

I have faced similar issue, Django swagger, that wont work for protected(Token authenticated) APIs, Use drf-yasf instead, with same configuration follow the ink below

https://github.com/axnsan12/drf-yasg
Ankush Sahu
  • 578
  • 7
  • 13