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
django django-rest-framework oauth-2.0 swagger-2.0


source to share


No one has answered this question yet

See similar questions:

five
What is the "scopes" field of a swagger security schema object?

or similar:

18
Django REST Framework Swagger 2.0
five
Using Xamarin.Auth for OAuth2 Authentication - Username and Password?
2
Yii2 oauth2 client_credential token authentication
2
How to use third party authentication services in SPA without cookies?
1
Node.js interacts with external API with oauth2, auth without UI / client interface
1
OAuth2 response with client_id instead of refresh_token
1
Django REST Swagger with OAuth2 Authentication
0
Oauth2 health check
0
How to access (ask) token for user login
0
Implementing an Oauth2 social system to combine Django and social accounts



All Articles
Loading...
X
Show
Funny
Dev
Pics