Пример #1
0
    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
Пример #2
0
    def access_token(self, token, oauth_verifier):
        """Return request for access token value"""
        request = self.oauth_request(token, self.ACCESS_TOKEN_URL, oauth_verifier)
        response = self.fetch_response(request)
        params = parse_qs(response, keep_blank_values=False)
        
        user_data = dict()
        for key in 'user_id', 'screen_name':
            try:
                user_data[key] = params[key][0]
            except Exception:
                raise ValueError("'%s' not found in OAuth response." % key)

        return Token.from_string(response), user_data
Пример #3
0
    def auth_complete(self, oauth_token, oauth_verifier):
        """Return user, might be logged in"""
        name = self.AUTH_BACKEND_NAME + 'unauthorized_token_name'
        unauthed_token = self.request.session[name]
        del self.request.session[name]
        if not unauthed_token:
            raise ValueError('Missing unauthorized token')

        token = Token.from_string(unauthed_token)
        if token.key != oauth_token:
            raise ValueError('Incorrect tokens')

        access_token, user_data = self.access_token(token, oauth_verifier)
        return user_data
Пример #4
0
    def auth_complete(self, oauth_token, oauth_verifier):
        """Return user, might be logged in"""
        name = self.AUTH_BACKEND_NAME + 'unauthorized_token_name'
        unauthed_token = self.request.session[name]
        del self.request.session[name]
        if not unauthed_token:
            raise ValueError('Missing unauthorized token')

        token = Token.from_string(unauthed_token)
        if token.key != oauth_token:
            raise ValueError('Incorrect tokens')

        access_token = self.access_token(token, oauth_verifier)

        data = self.user_data(access_token)
        return data
Пример #5
0
 def access_token(self, token, oauth_verifier):
     """Return request for access token value"""
     request = self.oauth_request(token, self.ACCESS_TOKEN_URL, oauth_verifier)
     return Token.from_string(self.fetch_response(request))
Пример #6
0
 def unauthorized_token(self):
     """Return request for unauthorized token (first stage)"""
     request = self.oauth_request(token=None, url=self.REQUEST_TOKEN_URL)
     response = self.fetch_response(request)
     return Token.from_string(response)
Пример #7
0
 def unauthorized_token(self):
     """Return request for unauthorized token (first stage)"""
     request = self.oauth_request(token=None, url=self.REQUEST_TOKEN_URL)
     response = self.fetch_response(request)
     return Token.from_string(response)
Пример #8
0
 def access_token(self, token, oauth_verifier):
     """Return request for access token value"""
     request = self.oauth_request(token, self.ACCESS_TOKEN_URL,
                                  oauth_verifier)
     return Token.from_string(self.fetch_response(request))