def verify(self, req): """ Verifies returned user and extracts user information @param req: the GET data from the page call. @return: The users information @rtype: dict """ from lib.urlparse import parse_qsl from django.utils import simplejson as json auth_token = req["oauth_token"] auth_verifier = req["oauth_verifier"] dataset = OAuthTW.get_by_key_name(auth_token) token = Token(auth_token, dataset.secret) token.set_verifier(auth_verifier) self.client = Client(self.consumer, token) resp, content = self.client.request(self.access_token_url, "POST") #@UnusedVariable auth = dict(parse_qsl(content)) token = Token(auth['oauth_token'], auth['oauth_token_secret']) self.client = Client(self.consumer, token) resp, content = self.client.request(self.userinfo_url, "GET") #@UnusedVariable info = json.loads(content) info.update(auth) dataset.delete() return info
def verify(self, req): """ Verify the user and extract the keys needed to authenticate. @param req: Requests GET data """ from lib.urlparse import parse_qsl code = req['code'] params = { "client_id":self.pubkey, "client_secret":self.Client.client_secret, "code":code, "redirect_uri":self.callback } resp, content = self.Client.request(self.access_token_url, method="POST", params=params) #@UnusedVariable data = dict(parse_qsl(content)) return data
def redirect(self, callback): """ Initiates a oAuth authentication request. @param callback: The callback URL @return: The URL to redirect the user to """ from lib.urlparse import parse_qsl from urllib import urlencode #@UnresolvedImport self.client = Client(self.consumer) resp, content = self.client.request(self.request_token_url, "POST", body=urlencode({"oauth_callback": callback})) if resp['status'] != '200': raise Exception("Invalid response %s." % resp['status']) request_token = dict(parse_qsl(content)) OAuthTW( key_name=request_token['oauth_token'], secret=request_token['oauth_token_secret'], service="twitter" ).put() return "%s?oauth_token=%s" % (self.authorize_url, request_token['oauth_token'])