예제 #1
0
def create_token(role):
    from aleph.serializers.roles import RoleSchema
    role, _ = RoleSchema().dump(role)
    role.pop('created_at', None)
    role.pop('updated_at', None)
    exp = datetime.utcnow() + timedelta(days=7)
    payload = {'role': role, 'exp': exp}
    return jwt.encode(payload, settings.SECRET_KEY)
예제 #2
0
 def to_token(self, scope=None, role=None):
     exp = datetime.utcnow() + timedelta(days=1)
     payload = {
         'id': self.id,
         'exp': exp,
         'roles': list(self.roles),
         'is_admin': self.is_admin
     }
     if scope is not None:
         payload['scope'] = scope
     if role is not None:
         from aleph.serializers.roles import RoleSchema
         role, _ = RoleSchema().dump(role)
         role.pop('created_at', None)
         role.pop('updated_at', None)
         payload['role'] = role
     return jwt.encode(payload, settings.SECRET_KEY)