$ pip install django-oauth2-provider
INSTALLED_APPS = (
# ...
'provider',
'provider.oauth2',
)
The default settings are available in provider.constants.
Add provider.oauth2.urls to your root urls.py file.
url(r'^oauth2/', include('provider.oauth2.urls', namespace = 'oauth2')),
Note
The namespace argument is required.
$ python manage.py syncdb
$ python manage.py migrate
Note
To find out which type of client you need to create, read Section 2.1.
To create a new entry, simply use the django admin panel.
Your client interface – I mean by that your iOS code, HTML code, or whatever else language – just have to submit a POST request at the url /oauth2/access_token with the following fields :
This is only one way to authenticate with OAuth 2, there is other methods but I will only show you the PasswordGrant type one in this quick “Getting started” guide.
Note
Remember that you SHOULD always use HTTPS for all your OAuth 2 requests otherwise you won’t be secured.
Now you can use the command line to check that your local configuration is working :
$ 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/
Here is the response you should get :
{"access_token": "<your-access-token>", "scope": "read", "expires_in": 86399, "refresh_token": "<your-refresh-token>"}