Ansuman Bebarta Ansuman Bebarta - 1 month ago 13
Python Question

Django restframework browsable api login with ouath

I have created a sample api by using djangorestframework which worked fine and I could use browsable api without any problem. Then I added outh2 authentication as mentioned on official website which also worked fine. I can use following to get access token.

curl -X POST -d "client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&grant_type=password&username=YOUR_USERNAME&password=YOUR_PASSWORD" http://localhost:8000/oauth2/access_token/


I can also use curl to browse my api by using access token.

But while using browsable api I can't browse my api due to obvious reason that browsable api is neither getting any access token nor using any. I think I need to have login for this. So I am not getting where can I customise the current login I am having to use oauth.

Answer

Web browsers don't generally let you set custom headers, so there's no way you can provide your OAuth token.

In general, if you want to use the browsable API then you need to allow session based (i.e. cookie based auth).

You can allow both authentication methods, perhaps restricting session auth for development if that's necessary.

I hope that helps.

Comments