4

I am using django, rest_framework and rest_framework_swagger to build an api with docs.

How do i select an authentication scheme? Right now i am using oauth2 password based authentication to obtain my token and use Bearer {{access_token}} in my header. The method i have used here was acquired from my previous work place.

Swagger works when my end points work for anonymous users. It fails to display the end points when they require authentication header.

I tried below code in vein

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

SWAGGER_SETTINGS = {
'SECURITY_DEFINITIONS': {
    "oauth": {
        "type": "oauth2",
        "tokenUrl": "http://127.0.0.1:8000/o/token",
        "flow": "password",
        "scopes": {
            "admin": "admin scope",
            "user": "users scope"
        }
    }

when i click on Authorise button on top right and again Authorise on the popup, the page leads to http://127.0.0.1:8000/docs/null&redirect_uri=http%3A%2F%2F127.0.0.1%3A8000%2Fdocs%2Fo2c.html&realm=your-realms&client_id=your-client-id&scope=admin%2Cuser&state=undefined

I found these pages usefull: OpenAPI, Blog Post on Swagger and OAuth2, What are scopes and Swagger tutorial

Community
  • 1
  • 1
Manoj
  • 547
  • 8
  • 16

1 Answers1

0

I ran into the same issue, maybe you are also using an older version of django-rest-swagger.

Use latest version i.e django-rest-swagger==2.2.0

kartheek
  • 6,434
  • 3
  • 42
  • 41