What are the settings for django rest framework swagger open api defining security object for oauth2 thread being password?

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

How do I choose an authentication scheme? Right now I am using oauth2 password based authentication to get my token and use the Bearer {{access_token}} in my header. The method I used here was derived from my previous workstation.

Swagger works when my endpoints are running for anonymous users. It cannot display endpoints when they need an authentication header.

I tried under 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 the Authorize button in the right and top corner and log in to 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 helpful: OpenAPI , Blog Post About Swagger and OAuth2 , What Are Scope And Swagger Tutorial

+3


source to share





All Articles