Esempio n. 1
0
 def consume(self, userid: str, token: str, registry=None):
     key_name = self.get_key(userid, token)
     conn = get_redis_conn(registry)
     cred_token = conn.get(key_name)
     if cred_token:
         cred_token = cred_token.decode()
         return Credentials.load(userid, cred_token, registry)
Esempio n. 2
0
 def create(self, credentials, expires=30, registry=None):
     assert isinstance(credentials, Credentials)  # Test
     one_time_token = _generate_token()
     key_name = self.get_key(credentials.userid, one_time_token)
     conn = get_redis_conn(registry)
     conn.setex(key_name, expires, credentials.token)
     return one_time_token
Esempio n. 3
0
 def consume(self, token: str, registry=None):
     key_name = self.get_key(token)
     conn = get_redis_conn(registry)
     payload = conn.get(key_name)
     if payload:
         payload = payload.decode()
         return json.loads(payload)
Esempio n. 4
0
 def load(cls, userid, token, registry=None):
     if registry is None:
         registry = get_current_registry()
     key = "{}.{}.{}".format(cls.prefix, userid, token)
     conn = get_redis_conn(registry)
     payload = conn.get(key)
     if payload:
         payload = payload.decode()
         data = json.loads(payload)
         inst = cls(registry=registry, **data)
         inst.reset_expire()
         return inst
Esempio n. 5
0
 def create(self, payload: dict, expires: int = 1200, registry=None):
     token = _generate_token(length=70)
     conn = get_redis_conn(registry)
     key_name = self.get_key(token)
     conn.setex(key_name, expires, json.dumps(payload))
     return token
Esempio n. 6
0
 def validate(self, userid: str, token: str, registry=None):
     key_name = self.get_key(userid, token)
     conn = get_redis_conn(registry)
     return bool(conn.exists(key_name))
Esempio n. 7
0
 def validate(self, token: str, registry=None):
     conn = get_redis_conn(registry)
     key_name = self.get_key(token)
     return bool(conn.exists(key_name))
Esempio n. 8
0
 def _conn(self):
     return get_redis_conn(self.registry)