This is working example of a Django service with Piston API authenticated with OAuth.
I spend quite some time trying to find a working combination of django piston oauth, as everything seemed broken one way or another. This is a working django project, ready to be installed on your machine so you can play and understand oauth with django and piston.
I did some modifications to remove csrf checks on oauth calls.
Finally I fetched oauth_client.py from this example https://github.com/clemesha/django-piston-oauth-example to test your oauth authentication.
- git clone git://github.com/glogiotatidis/django-piston-oauth-example.git # to clone
- cd django-piston-oauth-example
- bash scripts/build_environment.sh # to download and install django and dependencies
- source env/bin/activate # to activate the environment
- cd foo
- pythom manage.py syncdb # create dbs, create superuser
- python manage.py runserver
- login to admin panel through http://localhost:8000/admin/
- Create a new Consumer with Key: testkey and Secret: testsecret
- You are ready to go!
- Make sure that server runs
- Make sure that you have activated the environment
- Run oauth_client.py and follow the instructions
- You should end up with a oauth_token and a oauth_token_secret
Please if you find something missing or something that can be done in a better way, please let me know or even better submit a patch!
Two legged authentication
Guglielmo provided an example for two-legged authentication. Whether you have a two legged or three legged auth, depends on how you build the request.
Passing an empty access token key and secret, builds a two-legged authentication request. Example using twisted oauth-proxy plugin
twistd -n oauth_proxy –consumer-key testkey –consumer-secret testsecret –token “” –token-secret “”