[Solved]-Django REST Framework Swagger – Authentication Error

20πŸ‘

βœ…

I think I’ve found the solution.

In the settings.py, I added the following settings:

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

Then when I load the page, I just click on the Authorize button at the upper right and enter this value in the value text field:

Token <valid-token-string>

However, I still needed to set the permission class of the schema view to AllowAny. The auth token just let me switch from different users, allowing me to view different set of endpoints.

πŸ‘€Melvic Ybanez

0πŸ‘

Isn’t there a way to login as an admin, or any other user to view the docs.

If your only use token authentication, first create tokens for your users, then access the resources by setting the header

curl -X GET http://127.0.0.1:8000/api/example/ -H 'Authorization: Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b'
πŸ‘€Windsooon

Leave a comment