Пример #1
0
 def generate_request_token(self, oauth_request, oauth_consumer, oauth_callback=None):
     """Load the request token in the request
     
             :param oauth_request: oauth request
             :type oauth_request: :class:`oauth2.Request`
             :param oauth_consumer: oauth consumer
             :type oauth_consumer: :class:`oauth2.Consumer`
             :param oauth_callback: callback URL
             :type oauth_callback: :class:`string`
             
             :returns: :class:`oauth2.Token` with the new key and secret
             :raises: :class:`OAUTHException` if client key is invalid
     """
     client = OAUTH_Client.get_by_key_name(oauth_consumer.key)
     if client is not None:
         if oauth_callback is not None:
             token = OAUTH_Token.generate(oauth_consumer = client, token_callback=oauth_callback)
             oauthToken = oauth2.Token(token.token_key, token.token_secret)
             oauthToken.set_callback(oauth_callback)
         elif client.callback is not None:
             token = OAUTH_Token.generate(oauth_consumer = client, token_callback=client.callback)
             oauthToken = oauth2.Token(token.token_key, token.token_secret)
             oauthToken.set_callback(client.callback)
         else:
             token = OAUTH_Token.generate(oauth_consumer = client)
             oauthToken = oauth2.Token(token.token_key, token.token_secret)
         return oauthToken
     raise OAUTHException("Client key invalid") 
Пример #2
0
 def generate_access_token(self, token, oauth_consumer):
     """Generate the new access token
         
             :param token: Request token authorized
             :type token: :class:`oauth2.Token`
             :param oauth_consumer: Application requesting the access token
             :type oauth_consumer: :class:`oauth2.Consumer`
             :param user: User for the authorized token
             :type user: :class:`georemindme.models.User`
             
             :returns: :class:`oauth2.Token`
             :raises: :class:`OAUTHException` if the token key or consumer key are invalid
     """
     if token.verifier is None:
         raise OAUTHException('Unauthorized token')
     savedtoken = OAUTH_Token.get_by_key_name(token.key)        
     client = OAUTH_Client.get_by_key_name(oauth_consumer.key)
     if savedtoken is not None and client is not None:
         if token.verifier != savedtoken.token_verifier:
             raise OAUTHException("Token verifier invalid")
         accessToken = OAUTH_Token.generate(
                     oauth_consumer = client, 
                     oauth_user = savedtoken.oauth_user,
                     access = True
                     )
         savedtoken.delete() 
         oauthToken = oauth2.Token(accessToken.token_key, accessToken.token_secret)
         return oauthToken
     raise OAUTHException("Token or client key invalid")
Пример #3
0
 def fetch_consumer(self, oauth_request):
     """Load the consumer (key, secret) doing a request
     
         :param oauth_request: oauth request
         :type oauth_request: :class:`oauth2.Request`
     """
     key = oauth_request.get_parameter('oauth_consumer_key')
     if key is not None:
         client = OAUTH_Client.get_by_key_name(key)
         if client is None:
             raise OAUTHException("Client key invalid")
         return oauth2.Consumer(client.client_key, client.client_secret)
     return key
Пример #4
0
 def fetch_consumer(self, oauth_request):
     """Load the consumer (key, secret) who is doing a request
     
             :param oauth_request: oauth request
             :type oauth_request: :class:`oauth2.Request`
             
             :retuns: :class:`oauth2.Consumer`
             :raises: :class:`OAUTHException` if the client key is invalid
     """
     key = oauth_request.get_parameter('oauth_consumer_key')
     if key is not None:
         client = OAUTH_Client.get_by_key_name(key)
         if client is None:
             raise OAUTHException("Client key invalid")
         return oauth2.Consumer(client.client_key, client.client_secret)
     return key
Пример #5
0
 def _get_client(oauthRequest):
     """Return the client doing the oauth request
     
         :param oauthRequest: A valid oauth request
         :type oauthRequest: :class:`oauth2.Request`
         :return: :class:`OAUTH_Client
         :raises: :class:`OAUTHException`
     """
     if not isinstance(oauthRequest, oauth2.Request):
         oauthRequest = _get_oauth_request(oauthRequest)
     client_key = oauthRequest.get_parameters('oauth_consumer_key')
     if not client_key:#la peticion oauth no es valida
         raise OAUTHException("No 'oauth_consumer_key' in request")
     client = OAUTH_Client.get_by_key_name(client_key)
     if not client:#el usuario no existe
         raise OAUTHException("Invalid client in request")
     return client
Пример #6
0
 def fetch_request_token(self, oauth_request, oauth_consumer, oauth_callback=None):
     """Load the token in the request
     
         :param oauth_request: oauth request
         :type oauth_request: :class:`oauth2.Request`
         :param oauth_consumer: oauth consumer
         :type oauth_consumer: :class:`oauth2.Consumer`
         :param oauth_callback: callback URL
         :type oauth_callback: :class:`string`
     """
     client = OAUTH_Client.get_by_key_name(oauth_consumer.key)
     """
     try:
         key = oauth_request.get_parameter('oauth_token')
     except:
         key = None
     #buscar el token en la BD
     if key is not None:
         token = self.fetch_token(oauth_request)
         if token.oauth_client.key != oauth_consumer.key:
             raise OAUTHException("Token key invalid")
         oauthToken = oauth2.Token(token.token_key, token.token_secret)
         if oauth_callback is not None:
             token.token_callback(oauth_callback)
             token.put()
             oauthToken.set_callback(oauth_callback)
         elif client.callback is not None:
             token.token_callback(client.callback)
             token.put()
             oauthToken.set_callback(oauth_callback)              
     #el token no existe, crear uno nuevo
     """
     if oauth_callback is not None:
         token = OAUTH_Token.generate(oauth_consumer = client, token_callback=oauth_callback)
         oauthToken = oauth2.Token(token.token_key, token.token_secret)
         oauthToken.set_callback(oauth_callback)
     elif client.callback is not None:
         token = OAUTH_Token.generate(oauth_consumer = client, token_callback=client.callback)
         oauthToken = oauth2.Token(token.token_key, token.token_secret)
         oauthToken.set_callback(client.callback)
     else:
         token = OAUTH_Token.generate(oauth_consumer = client)
         oauthToken = oauth2.Token(token.token_key, token.token_secret)
     return oauthToken
Пример #7
0
 def fetch_access_token(self, token, oauth_consumer):
     """Generate the new access token
         
         :param token: Request token authorized
         :type token: :class:`oauth2.Token`
         :param oauth_consumer: Application requesting the access token
         :type oauth_consumer: :class:`oauth2.Consumer`
         :param user: User for the authorized token
         :type user: :class:`georemindme.models.User`
     """
     if token.verifier is None:
         raise OAUTHException('Unauthorized token')
     token = OAUTH_Token.get_by_key_name(token.key)        
     client = OAUTH_Client.get_by_key_name(oauth_consumer.key)
     #los token de acceso, tienen el mismo verifier
     accessToken = OAUTH_Token.generate(
                 oauth_consumer = client, 
                 oauth_user = token.oauth_user,
                 access = True
                 )
     token.delete()
     #el token a devolver
     oauthToken = oauth2.Token(accessToken.token_key, accessToken.token_secret)
     return oauthToken