Ejemplo n.º 1
0
 def test_New_always_creates_new_keydata(self):
     currentKeyData = KeyData.find_by_code('client_id2',
                                           'authorization_code2')
     KeyData('client_id2', 'user_id2', 'access_key2', 'refresh_key2',
             'authorization_code3')
     newKeyData = KeyData.find_by_code('client_id2', 'authorization_code3')
     self.assertNotEqual(currentKeyData, newKeyData)
Ejemplo n.º 2
0
 def test_Access_key_and_refresh_key_can_be_retrieved_by_client_id_and_authorizaton_code(
         self):
     clientData = KeyData.find_by_code('client_id2', 'authorization_code2')
     self.assertEqual(clientData.access_key, 'access_key2')
     self.assertEqual(clientData.refresh_key, 'refresh_key2')
     self.assertEqual(
         "KeyData(client_id=client_id2, user_id=user_id2, access_key=access_key2, refresh_key=refresh_key2, authorization_code=authorization_code2)",
         "{0}".format(clientData))
Ejemplo n.º 3
0
    def find(klass, access_key, _called_at = None):
        if _called_at is None:
            _called_at = time.time()
        ret = klass.query.filter_by(access_key=access_key).first()
        if ret is not None and ret.expire_time <= int(_called_at):
            ret.rm()
            ret = None
        return ret
        
        
    @classmethod
    def new(cls, access_key, tokeninfo, expires_in):
        if cls.find(access_key):
            raise DuplicateAccessKey()
        tiba = cls(access_key, tokeninfo, expires_in)
        tiba.save()
        return tiba
    
    def __init__(self, access_key, tokeninfo, expires_in):
        self.access_key = access_key
        self.tokeninfo = tokeninfo
        self.expire_time = time.time() + expires_in

    @classmethod
    def removeAllForKey(cls, key):
        instances = cls.query.filter_by(access_key=key.access_key).all()
        for instance in instances:
            instance.rm()

KeyData.subscribe(TokenInfoByAccessKey.removeAllForKey, "pre_rm")
Ejemplo n.º 4
0
 def persist_authorization_code(self, client_id, code, scope):
     keyData = KeyData(client_id=client_id,
                       authorization_code=code,
                       user_id=self.getCurrentUser().userid)
     keyData.save()
Ejemplo n.º 5
0
 def from_refresh_token(self,client_id, refresh_token, scope):
     if scope != '':
         raise ScopeMustBeEmpty()
     return KeyData.find_by_refresh_token(client_id, refresh_token)
Ejemplo n.º 6
0
 def test_KeyData_can_be_created_with_client_id__user_id__acess_key__refresh_key_and_authorization_code(self):
     self.clientData = KeyData.new('client_id', 'user_id', 'access_key', 'refresh_key')
Ejemplo n.º 7
0
 def None_is_returned_for_nonexistent_user_id(self):
     self.assertEquals(None, KeyData.find('client_id', 'nonexistent'))
Ejemplo n.º 8
0
 def KeyData_can_be_created_with_client_id__user_id__acess_key__and__refresh_key(self):
     self.clientData = KeyData.new('client_id', 'user_id', 'access_key', 'refresh_key')
Ejemplo n.º 9
0
 def setUp(self):
     KeyData('client_id2', 'user_id2', 'access_key2', 'refresh_key2',
             'authorization_code2')
Ejemplo n.º 10
0
 def test_KeyData_can_be_created_with_client_id__user_id__acess_key__refresh_key_and_authorization_code(
         self):
     self.clientData = KeyData.new('client_id', 'user_id', 'access_key',
                                   'refresh_key')
Ejemplo n.º 11
0
 def from_refresh_token(self, form):
     return KeyData.find_by_refresh_token(form.client_id.data,
                                          form.refresh_token.data)
Ejemplo n.º 12
0
 def test_None_is_returned_for_nonexistent_client_id_when_looking_up_keydata_by_code(
         self):
     clientData = KeyData.find_by_code('nonexistent', 'authorization_code2')
     self.assertEqual(clientData, None)
Ejemplo n.º 13
0
 def persist_token_information(self, tokenInfo, clientId, userId):
     keydata = KeyData.new(clientId, userId, tokenInfo.access_token,
                           tokenInfo.refresh_token)
     TokenInfoByAccessKey.new(tokenInfo.access_token, keydata,
                              tokenInfo.expires_in)
Ejemplo n.º 14
0
 def from_authorization_code(self, client_id, code, scope):
     return KeyData.find_by_code(client_id=client_id,authorization_code = code)
Ejemplo n.º 15
0
 def persist_authorization_code(self, client_id, code, scope):
     keyData = KeyData(client_id=client_id, authorization_code = code, user_id=self.getCurrentUser().userid)
     keyData.save()
Ejemplo n.º 16
0
 def from_refresh_token(self,form):
     return KeyData.find_by_refresh_token(form.client_id.data, form.refresh_token.data)
Ejemplo n.º 17
0
 def persist_token_information(self, tokenInfo, clientId, userId):
     keydata = KeyData.new(clientId, userId, tokenInfo.access_token, tokenInfo.refresh_token)
     TokenInfoByAccessKey.new(tokenInfo.access_token, keydata, tokenInfo.expires_in)
Ejemplo n.º 18
0
 def test_None_is_returned_for_nonexistent_refresh_token_when_looking_up_keydata_by_refresh_token(
         self):
     clientData = KeyData.find_by_refresh_token('client_id2', 'nonexistent')
     self.assertEqual(clientData, None)
Ejemplo n.º 19
0
 def from_authorization_code(self, client_id, code, scope):
     return KeyData.find_by_code(client_id=client_id,
                                 authorization_code=code)
Ejemplo n.º 20
0
 def test_Access_key_and_refresh_key_can_be_retrieved_by_client_id_and_authorizaton_code(self):
     clientData = KeyData.find_by_code('client_id2', 'authorization_code2')
     self.assertEqual(clientData.access_key,'access_key2')
     self.assertEqual(clientData.refresh_key,'refresh_key2')
     self.assertEqual("KeyData(client_id=client_id2, user_id=user_id2, access_key=access_key2, refresh_key=refresh_key2, authorization_code=authorization_code2)",
                       "{0}".format(clientData))
Ejemplo n.º 21
0
 def test_None_is_returned_for_nonexistent_client_id_when_looking_up_keydata_by_code(self):
     clientData = KeyData.find_by_code('nonexistent', 'authorization_code2')
     self.assertEqual(clientData, None)
Ejemplo n.º 22
0
 def access_key_and_refresh_key_can_be_retrieved_by_client_id_and_user_id(self):
     clientData = KeyData.find('client_id', 'user_id')
     self.assertEquals(clientData.access_key,'access_key')
     self.assertEquals(clientData.refresh_key,'refresh_key')
     self.assertEquals("KeyData(client_id=client_id, user_id=user_id, access_key=access_key, refresh_key=refresh_key, authorization_code=None)",
                       "{0}".format(clientData))
Ejemplo n.º 23
0
 def test_None_is_returned_for_nonexistent_refresh_token_when_looking_up_keydata_by_refresh_token(self):
     clientData = KeyData.find_by_refresh_token('client_id2', 'nonexistent')
     self.assertEqual(clientData, None)
Ejemplo n.º 24
0
 def None_is_returned_for_none_as_client_id(self):
     self.assertEquals(None, KeyData.find(None, 'user_id'))
Ejemplo n.º 25
0
 def test_New_always_creates_new_keydata(self):
     currentKeyData = KeyData.find_by_code('client_id2', 'authorization_code2')
     KeyData('client_id2', 'user_id2', 'access_key2', 'refresh_key2', 'authorization_code3')
     newKeyData = KeyData.find_by_code('client_id2', 'authorization_code3')
     self.assertNotEqual(currentKeyData, newKeyData)
Ejemplo n.º 26
0
 def TokenInfo_can_be_stored_by_access_key(self):
     self.keydata = KeyData.new('client_id', 'user_id', 'access_key', 'refresh_key')
     self.tiba = TokenInfoByAccessKey.new('access key', self.keydata, 20)
Ejemplo n.º 27
0
 def persist_token_information(self, client_id, scope, access_token, token_type, expires_in, refresh_token, data):
     keydata = KeyData.new(client_id, data.user_id, access_token, refresh_token)
     TokenInfoByAccessKey.new(access_token, keydata, expires_in)