Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django OAuth Toolkit and Django Rest Swagger Integration

I'm using OAuthToolkit and DjangoRestSwagger. I've created an application using Django Admin, and now I've client_id and client_secret.

I want to generate the token using client_id and client_secret. Currently, I use curl to generate the token.

curl -X POST -d "grant_type=client_credentials" -u"client_id:client_secret" http://localhost:8000/o/token/

How can I do it using the Swagger docs.? Basically, how can integrate third party(OAuthToolkit) API URLs with Swagger?

Currently, I've an Authorize button which takes api_key value, ie the token.

Here's my Swagger settings.

SWAGGER_SETTINGS = {
    'SECURITY_DEFINITIONS': {
        'token': {
            'type': 'apiKey',
            'name': 'AUTHORIZATION',
            'in': 'header',
        }
    },
}
like image 385
PythonEnthusiast Avatar asked Nov 19 '22 04:11

PythonEnthusiast


1 Answers

Not certain about django-rest-swagger but if you are looking for an alternative with gauranteed support for oauth you can use drf-yasg (yet another swagger generator)

Documentation for yasg adding oauth paths to swagger

like image 158
tread Avatar answered Dec 28 '22 23:12

tread