示例#1
0
    def setUp(self):
        # Create client test authentication token
        self.client_token = 'SOMEAUTHTESTINGTOKENHERE2122'
        token_info = {
            'timestamp': '12/12/12 12:12:00',
            'client_id': 'test123123123',
            'grant_type': 'client'

        }
        r_client.hmset(self.client_token, token_info)
        r_client.expire(self.client_token, 5)

        # Create username test authentication token
        self.user_token = 'SOMEAUTHTESTINGTOKENHEREUSERNAME'
        token_info = {
            'timestamp': '12/12/12 12:12:00',
            'client_id': 'testuser',
            'grant_type': 'password',
            'user': '******'
        }
        r_client.hmset(self.user_token, token_info)
        r_client.expire(self.user_token, 5)

        # Create test access limit token
        self.user_rate_key = '[email protected]_daily_limit'
        r_client.setex(self.user_rate_key, 5, 2)
        super(OAuth2BaseHandlerTests, self).setUp()
示例#2
0
 def setUp(self):
     self.token = 'TESTINGOAUTHSTUFF'
     self.header = {'Authorization': 'Bearer ' + self.token}
     r_client.hset(self.token, 'timestamp', '12/12/12 12:12:00')
     r_client.hset(self.token, 'grant_type', 'client')
     r_client.expire(self.token, 20)
     super(OauthTestingBase, self).setUp()
示例#3
0
    def setUp(self):
        # Create client test authentication token
        self.client_token = 'SOMEAUTHTESTINGTOKENHERE2122'
        token_info = {
            'timestamp': '12/12/12 12:12:00',
            'client_id': 'test123123123',
            'grant_type': 'client'
        }
        r_client.hmset(self.client_token, token_info)
        r_client.expire(self.client_token, 5)

        # Create username test authentication token
        self.user_token = 'SOMEAUTHTESTINGTOKENHEREUSERNAME'
        token_info = {
            'timestamp': '12/12/12 12:12:00',
            'client_id': 'testuser',
            'grant_type': 'password',
            'user': '******'
        }
        r_client.hmset(self.user_token, token_info)
        r_client.expire(self.user_token, 5)

        # Create test access limit token
        self.user_rate_key = '[email protected]_daily_limit'
        r_client.setex(self.user_rate_key, 5, 2)
        super(OAuth2BaseHandlerTests, self).setUp()
示例#4
0
    def setUp(self):
        self.client_token = 'SOMEAUTHTESTINGTOKENHERE2122'
        r_client.hset(self.client_token, 'timestamp', '12/12/12 12:12:00')
        r_client.hset(self.client_token, 'client_id', 'test123123123')
        r_client.hset(self.client_token, 'grant_type', 'client')
        r_client.expire(self.client_token, 5)

        self.headers = {'Authorization': 'Bearer ' + self.client_token}
        super(RESTHandlerTestCase, self).setUp()
示例#5
0
    def set_token(self, client_id, grant_type, user=None, timeout=3600):
        """Create access token for the client on redis and send json response

        Parameters
        ----------
        client_id : str
            Client that requested the token
        grant_type : str
            Type of key being requested
        user : str, optional
            If password grant type requested, the user requesting the key.
        timeout : int, optional
            The timeout, in seconds, for the token. Default 3600

        Returns
        -------
        Writes token information JSON in the form expected by RFC6750:
        {'access_token': token,
         'token_type': 'Bearer',
         'expires_in': timeout}

         access_token: the actual token to use
         token_type: 'Bearer', which is the expected token type for Oauth2
         expires_in: time to token expiration, in seconds.
        """
        token = self.generate_access_token()

        token_info = {
            'timestamp': datetime.datetime.now().strftime('%m-%d-%y %H:%M:%S'),
            'client_id': client_id,
            'grant_type': grant_type
        }
        if user:
            token_info['user'] = user

        r_client.hmset(token, token_info)
        r_client.expire(token, timeout)
        if grant_type == 'password':
            # Check if client has access limit key, and if not, create it
            limit_key = '%s_%s_daily_limit' % (client_id, user)
            limiter = r_client.get(limit_key)
            if limiter is None:
                # Set limit to 5,000 requests per day
                r_client.setex(limit_key, 86400, 5000)

        self.write({
            'access_token': token,
            'token_type': 'Bearer',
            'expires_in': timeout
        })
        self.finish()
示例#6
0
文件: oauth2.py 项目: antgonza/qiita
    def set_token(self, client_id, grant_type, user=None, timeout=3600):
        """Create access token for the client on redis and send json response

        Parameters
        ----------
        client_id : str
            Client that requested the token
        grant_type : str
            Type of key being requested
        user : str, optional
            If password grant type requested, the user requesting the key.
        timeout : int, optional
            The timeout, in seconds, for the token. Default 3600

        Returns
        -------
        Writes token information JSON in the form expected by RFC6750:
        {'access_token': token,
         'token_type': 'Bearer',
         'expires_in': timeout}

         access_token: the actual token to use
         token_type: 'Bearer', which is the expected token type for Oauth2
         expires_in: time to token expiration, in seconds.
        """
        token = self.generate_access_token()

        token_info = {
            'timestamp': datetime.datetime.now().strftime('%m-%d-%y %H:%M:%S'),
            'client_id': client_id,
            'grant_type': grant_type
        }
        if user:
            token_info['user'] = user

        r_client.hmset(token, token_info)
        r_client.expire(token, timeout)
        if grant_type == 'password':
            # Check if client has access limit key, and if not, create it
            limit_key = '%s_%s_daily_limit' % (client_id, user)
            limiter = r_client.get(limit_key)
            if limiter is None:
                # Set limit to 5,000 requests per day
                r_client.setex(limit_key, 86400, 5000)

        self.write({'access_token': token,
                    'token_type': 'Bearer',
                    'expires_in': timeout})
        self.finish()