Skip to content

Instantly share code, notes, and snippets.

@clemesha
Created April 21, 2010 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clemesha/374115 to your computer and use it in GitHub Desktop.
Save clemesha/374115 to your computer and use it in GitHub Desktop.

Getting OAuth Working with django-piston

###Resources (some are just "How OAuth works notes aka w/ Twitter", some are "django-piston specific")

###Preliminary steps and Code (django-piston "blogpost" example + 'piston.authentication.OAuthAuthentication'):

"You are unauthenticated. (API protected by OAuth)." In browser:
http://localhost:8000/api/posts.json

Add/Auth new creds/token "by hand":
http://localhost:8000/admin/piston/token/

Authorizing Token (logged in as Admin):
http://localhost:8000/api/oauth/authorize/?oauth_token=3Szw3AU5bkMV6QTVnR

###Edited file for Django 'blogserver' Example from django-piston

vim blogserver/piston/templates/oauth/challenge.html
vim blogserver/piston/templates/oauth/authorize_token.html
vim blogserver/piston/templates/api/mails/consumer_accepted.txt

vim blogserver/settings.py
vim oauth_client.py 
vim python-oauth2/oauth2/__init__.py

###Running Client

$ python oauth_client.py 
$ curl -u testuser:foobarr "http://127.0.0.1:8000/api/posts.json" -F "title=test" # No OAuth
$ curl -u testuser:foobar "http://127.0.0.1:8000/api/posts.json" -F "title=test" -F "content=blah"   # using OAuth Twisted proxy

###OAuth Twisted Proxy

pip -E piston_env/ install twisted
cd piston_env/
git clone git://github.com/mojodna/oauth-proxy.git
source bin/activate
twistd -n oauth_proxy --consumer-key testkey --consumer-secret testsecret --token 3Szw3AU5bkMV6QTVnR --token-secret gNyCyxF4HjPUTs5pMBzCnSduRpGJKCxA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment