Example #1
0
def payload_handler(identity):
    result = flask_jwt._default_jwt_payload_handler(identity)
    result.update({
        'user_id': identity.id,
        'username': identity.username,
        'roles': [role.name for role in identity.roles]
    })
    return result
Example #2
0
def jwt_payload(identity):
   """Serializes our identity object and stores additional user payload data"""

   payload = _default_jwt_payload_handler(identity)
   payload.update({
      'okta_user_id': identity.okta_user_id,
      'apps': identity.apps
   })
   return payload
Example #3
0
def jwt_payload_handler(identity):
    payload = _default_jwt_payload_handler(identity)
    user = Users.query.filter(Users.username == payload['identity']).scalar()
    # If user has a normal token (with expiration date), handle as usual
    # Also, force admin user to have expiring token for security reasons
    if not user or user.token_expires or user.role == Users.ADMIN:
        return payload
    # Put maximal datetime as a timestamp to make non-expiring token
    payload['exp'] = datetime.datetime.max
    return payload
Example #4
0
def test_object_vs_dict_handling_in_default_jwt_payload_handler(app):
    """Test dicts do not cause Attribute error when looking for id key or field.
    """
    from flask_jwt import _default_jwt_payload_handler

    class IDT(object):
        def __init__(self):
            self.id = "456"
            self.name = "tony"

    identity1 = IDT()

    identity2 = {"id": "123456", "name": "bob"}

    result = _default_jwt_payload_handler(identity1)
    assert "identity" in result
    assert result["identity"] == identity1.id

    # This did explode with attribute error when a dict was used:
    result = _default_jwt_payload_handler(identity2)
    assert "identity" in result
    assert result["identity"] == identity2['id']
Example #5
0
def make_payload(identity):
    print("pase")
    result = _default_jwt_payload_handler(identity)
    result['identity'] = {'id': identity.id, 'username':  identity.username}
    return result
Example #6
0
def JWTExtendedInfoMaker(identity):
    tokenInfo = flask_jwt._default_jwt_payload_handler(identity)
    if "permissions" in identity.__dict__:
        tokenInfo["permissions"] = identity.permissions
    tokenInfo["actor"] = identity.actor
    return tokenInfo
Example #7
0
    'DEBUG': False,
    'SECRET_KEY': 'secret_xxx',
    'JWT_AUTH_URL_RULE': None,
})
CORS(app)
Pony(app)
CRYPT_CONTEXT = CryptContext(schemes=['scrypt', 'bcrypt'])

day_names = list(calendar.day_name)

logging.basicConfig(level=logging.INFO)

jwt = JWT(None, None, lambda payload: db.Student.get(id=payload['id']))
jwt.auth_request_callback = None
jwt.jwt_payload_callback = lambda identity: dict(
    _default_jwt_payload_handler(identity), username=identity.name)
jwt.init_app(app)


def do_404(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except FileNotFoundError:
            return flask.abort(404)

    return wrapper


def parse_time_constraint(param):
Example #8
0
def payload_handler(identity):
    payload = _default_jwt_payload_handler(identity)

    payload["jti"] = identity.jti

    return payload
Example #9
0
def make_payload(user_identity):
    user_identity.id = None
    payload = _default_jwt_payload_handler(user_identity)
    payload['username'] = user_identity.username
    return payload