Ejemplo n.º 1
0
    def fetch_request_token(self, oauth_consumer, oauth_callback):

        if oauth_consumer.key != self.consumer.key:
            raise OAuthError('Consumer key does not match.')

        # OAuth 1.0a: if there is a callback, check its validity
        callback = None
        callback_confirmed = False
        if oauth_callback:
            if oauth_callback != OUT_OF_BAND:
                if check_valid_callback(oauth_callback):
                    callback = oauth_callback
                    callback_confirmed = True
                else:
                    raise oauth.OAuthError('Invalid callback URL.')

        # Not going to implement scope just yet-so just hard code this for now
        # We create a default resource if it doesn't already exist.
        resource = Resource.get_or_insert("default", name="default")

        #try:
        #    resource = Resource.objects.get(name=self.scope)
        #except:
        #    raise OAuthError('Resource %s does not exist.' % escape(self.scope))

        self.request_token = Token.create_token(consumer=self.consumer,
                                                        token_type=Token.REQUEST,
                                                        timestamp=self.timestamp,
                                                        resource=resource,
                                                        callback=callback,
                                                        callback_confirmed=callback_confirmed)

        return self.request_token
Ejemplo n.º 2
0
    def fetch_request_token(self, oauth_consumer, oauth_callback):
        logger.debug("!!! In MockOAuthDataStore.fetch_request_token  args: %s"%locals())
        
        if oauth_consumer.key != self.consumer.key:
            raise OAuthError('Consumer key does not match.')
            
        # OAuth 1.0a: if there is a callback, check its validity
        callback = None
        callback_confirmed = False
        if oauth_callback:
            if oauth_callback != OUT_OF_BAND:
                if check_valid_callback(oauth_callback):
                    callback = oauth_callback
                    callback_confirmed = True
                else:
                    raise oauth.OAuthError('Invalid callback URL.')

        #not going to implement scope just yet-so just hard code this for now
        resource = Resource.get_default()
        
        #try:
        #    resource = Resource.objects.get(name=self.scope)
        #except:
        #    raise OAuthError('Resource %s does not exist.' % escape(self.scope))
        
        self.request_token = Token.create_token(consumer=self.consumer,
                                                        token_type=Token.REQUEST,
                                                        timestamp=self.timestamp,
                                                        resource=resource,
                                                        callback=callback,
                                                        callback_confirmed=callback_confirmed)
        
        return self.request_token
Ejemplo n.º 3
0
    def fetch_request_token(self, oauth_consumer, oauth_callback):

        if oauth_consumer.key != self.consumer.key:
            raise OAuthError('Consumer key does not match.')

        # OAuth 1.0a: if there is a callback, check its validity
        callback = None
        callback_confirmed = False
        if oauth_callback:
            if oauth_callback != OUT_OF_BAND:
                if check_valid_callback(oauth_callback):
                    callback = oauth_callback
                    callback_confirmed = True
                else:
                    raise oauth.OAuthError('Invalid callback URL.')

        # Not going to implement scope just yet-so just hard code this for now
        # We create a default resource if it doesn't already exist.
        resource = Resource.get_or_insert("default", name="default")

        #try:
        #    resource = Resource.objects.get(name=self.scope)
        #except:
        #    raise OAuthError('Resource %s does not exist.' % escape(self.scope))

        self.request_token = Token.create_token(
            consumer=self.consumer,
            token_type=Token.REQUEST,
            timestamp=self.timestamp,
            resource=resource,
            callback=callback,
            callback_confirmed=callback_confirmed)

        return self.request_token
Ejemplo n.º 4
0
    def fetch_request_token(self, oauth_consumer, oauth_callback):
        logger.debug("!!! In MockOAuthDataStore.fetch_request_token  args: %s"%locals())
        
        if oauth_consumer.key != self.consumer.key:
            raise OAuthError('Consumer key does not match.')
            
        # OAuth 1.0a: if there is a callback, check its validity
        callback = None
        callback_confirmed = False
        if oauth_callback:
            if oauth_callback != OUT_OF_BAND:
                if check_valid_callback(oauth_callback):
                    callback = oauth_callback
                    callback_confirmed = True
                else:
                    raise oauth.OAuthError('Invalid callback URL.')

        #not going to implement scope just yet-so just hard code this for now
        resource = Resource.all().filter("name =","default")[0]
        
        #try:
        #    resource = Resource.objects.get(name=self.scope)
        #except:
        #    raise OAuthError('Resource %s does not exist.' % escape(self.scope))
        
        self.request_token = Token.create_token(consumer=self.consumer,
                                                        token_type=Token.REQUEST,
                                                        timestamp=self.timestamp,
                                                        resource=resource,
                                                        callback=callback,
                                                        callback_confirmed=callback_confirmed)
        
        return self.request_token
Ejemplo n.º 5
0
 def fetch_access_token(self, oauth_consumer, oauth_token, oauth_verifier):
     if (oauth_consumer.key_ == self.consumer.key_ and
             oauth_token.key_ == self.request_token.key_ and
             self.request_token.is_approved):
         # OAuth 1.0a: if there is a callback confirmed, check the verifier
         if ((self.request_token.callback_confirmed and
                 oauth_verifier == self.request_token.verifier) or
                 not self.request_token.callback_confirmed):
             self.access_token = Token.create_token(
                     consumer=self.consumer,
                     token_type=Token.ACCESS,
                     timestamp=self.timestamp,
                     user=self.request_token.user,
                     resource=self.request_token.resource)
             return self.access_token
     raise oauth.OAuthError("Consumer key or token key does not match. " +
                            "Make sure your request token is approved. " +
                            "Check your verifier too if you use OAuth 1.0a.")
Ejemplo n.º 6
0
    def lookup_token(self, token_type, token):
        if token_type == 'request':
            token_type = Token.REQUEST
        elif token_type == 'access':
            token_type = Token.ACCESS

        request_tokens = (Token.all().filter('key_ =', token).filter(
            'token_type =', token_type).fetch(1000))

        if len(request_tokens) == 1:
            self.request_token = request_tokens[0]
            return self.request_token
        elif len(request_tokens) == 0:
            logging.info("No token found")
            return None
        else:
            logging.info("%d tokens found" % len(request_tokens))
            raise Exception('More then one %s token matches token "%s"' %
                            (token_type, token))
Ejemplo n.º 7
0
 def fetch_access_token(self, oauth_consumer, oauth_token, oauth_verifier):
     if (oauth_consumer.key_ == self.consumer.key_
             and oauth_token.key_ == self.request_token.key_
             and self.request_token.is_approved):
         # OAuth 1.0a: if there is a callback confirmed, check the verifier
         if ((self.request_token.callback_confirmed
              and oauth_verifier == self.request_token.verifier)
                 or not self.request_token.callback_confirmed):
             self.access_token = Token.create_token(
                 consumer=self.consumer,
                 token_type=Token.ACCESS,
                 timestamp=self.timestamp,
                 user=self.request_token.user,
                 resource=self.request_token.resource)
             return self.access_token
     raise oauth.OAuthError(
         "Consumer key or token key does not match. " +
         "Make sure your request token is approved. " +
         "Check your verifier too if you use OAuth 1.0a.")
Ejemplo n.º 8
0
    def lookup_token(self, token_type, token):
        if token_type == 'request':
            token_type = Token.REQUEST
        elif token_type == 'access':
            token_type = Token.ACCESS
        
        logger.debug("!!! In GAEOAuthDataStore.lookup_token  key_:%s, token_type: %s"%(token,token_type))

        request_tokens = Token.all()\
            .filter('key_ =',token)\
            .filter('token_type =',token_type).fetch(1000)
        
        if len(request_tokens) == 1:
            self.request_token = request_tokens[0]
            return self.request_token
        elif len(request_tokens) == 0:
            return None
        else:
            raise Exception('More then one %s token matches token "%s"'%(token_type,token))
Ejemplo n.º 9
0
    def fetch_access_token(self, oauth_consumer, oauth_token, oauth_verifier):
        logger.debug("!!! IN MockOAuthDataStore.fetch_access_token  args: %s"%locals())

        if oauth_consumer.key_ == self.consumer.key_ \
        and oauth_token.key_ == self.request_token.key_ \
        and self.request_token.is_approved:
            # OAuth 1.0a: if there is a callback confirmed, check the verifier
            if (self.request_token.callback_confirmed \
            and oauth_verifier == self.request_token.verifier) \
            or not self.request_token.callback_confirmed:
                self.access_token = Token.create_token(consumer=self.consumer,
                                                               token_type=Token.ACCESS,
                                                               timestamp=self.timestamp,
                                                               user=self.request_token.user,
                                                               resource=self.request_token.resource)
                return self.access_token
        raise oauth.OAuthError('Consumer key or token key does not match. ' \
                        +'Make sure your request token is approved. ' \
                        +'Check your verifier too if you use OAuth 1.0a.')
Ejemplo n.º 10
0
    def lookup_token(self, token_type, token):
        if token_type == 'request':
            token_type = Token.REQUEST
        elif token_type == 'access':
            token_type = Token.ACCESS
        
        logger.debug("!!! In GAEOAuthDataStore.lookup_token  key_:%s, token_type: %s"%(token,token_type))

        request_tokens = Token.all()\
            .filter('key_ =',token)\
            .filter('token_type =',token_type).fetch(1000)
        
        if len(request_tokens) == 1:
            self.request_token = request_tokens[0]
            return self.request_token
        elif len(request_tokens) == 0:
            return None
        else:
            raise Exception('More then one %s token matches token "%s"'%(token_type,token))
Ejemplo n.º 11
0
    def fetch_access_token(self, oauth_consumer, oauth_token, oauth_verifier):
        logger.debug("!!! IN MockOAuthDataStore.fetch_access_token  args: %s"%locals())

        if oauth_consumer.key_ == self.consumer.key_ \
        and oauth_token.key_ == self.request_token.key_ \
        and self.request_token.is_approved:
            # OAuth 1.0a: if there is a callback confirmed, check the verifier
            if (self.request_token.callback_confirmed \
            and oauth_verifier == self.request_token.verifier) \
            or not self.request_token.callback_confirmed:
                self.access_token = Token.create_token(consumer=self.consumer,
                                                               token_type=Token.ACCESS,
                                                               timestamp=self.timestamp,
                                                               user=self.request_token.user,
                                                               resource=self.request_token.resource)
                return self.access_token
        raise oauth.OAuthError('Consumer key or token key does not match. ' \
                        +'Make sure your request token is approved. ' \
                        +'Check your verifier too if you use OAuth 1.0a.')
Ejemplo n.º 12
0
    def lookup_token(self, token_type, token):
        if token_type == 'request':
            token_type = Token.REQUEST
        elif token_type == 'access':
            token_type = Token.ACCESS

        request_tokens = (Token.all().
                filter('key_ =', token).
                filter('token_type =', token_type).
                fetch(1000))

        if len(request_tokens) == 1:
            self.request_token = request_tokens[0]
            return self.request_token
        elif len(request_tokens) == 0:
            logging.info("No token found")
            return None
        else:
            logging.info("%d tokens found" % len(request_tokens))
            raise Exception('More then one %s token matches token "%s"'%(token_type,token))