Skip to content

Instantly share code, notes, and snippets.

@makmac213
Last active August 29, 2015 14:20
Show Gist options
  • Save makmac213/01d2d5f129837dba9c3a to your computer and use it in GitHub Desktop.
Save makmac213/01d2d5f129837dba9c3a to your computer and use it in GitHub Desktop.
Odesk Api Callback URL Workaround (Django)
class OdeskView(View):
class LinkAccount(View):
def get(self, request, *args, **kwargs):
client = odesk.Client(settings.ODESK_API_KEY,
settings.ODESK_API_SECRET)
url = client.auth.get_authorize_url()
# need to store request token and request token secret
# so that callback url will not raise exception
# 'At first you need to call get_authorize_url'
request.session['request_token'] = client.auth.request_token
request.session['request_token_secret'] = client.auth.request_token_secret
return redirect(url)
class Callback(View):
def get(self, request, *args, **kwargs):
oauth_token = request.GET.get('oauth_token')
oauth_verifier = request.GET.get('oauth_verifier')
client = odesk.Client(settings.ODESK_API_KEY,
settings.ODESK_API_SECRET)
client.auth.key = settings.ODESK_API_KEY
client.auth.secret = settings.ODESK_API_SECRET
# retrieve current session stored request token and request token secret
client.auth.request_token = request.session.get('request_token')
client.auth.request_token_secret = request.session.get('request_token_secret')
token, secret = client.auth.get_access_token(oauth_verifier)
client = odesk.Client(settings.ODESK_API_KEY,
settings.ODESK_API_SECRET,
oauth_access_token=token,
oauth_access_token_secret=secret)
# Do your stuff here
# ...
# don't forget to return something
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment