flask_jwt.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:opp 作者: openpassphrase 项目源码 文件源码
def _jwt_required(realm):
    """Does the actual work of verifying the JWT data in the current request.
    This is done automatically for you by `jwt_required()` but you could call
    it manually. Doing so would be useful in the context of optional JWT access
    in your APIs.

    :param realm: an optional realm
    """
    token = _jwt.request_callback()

    if token is None:
        raise JWTError('Authorization Required',
                       'Request does not contain an access token',
                       headers={'WWW-Authenticate': 'JWT realm="%s"' % realm})

    try:
        payload = _jwt.jwt_decode_callback(token)
    except jwt.InvalidTokenError as e:
        raise JWTError('Invalid token', str(e))

    identity = _jwt.identity_callback(payload)

    if identity is None:
        raise JWTError('Invalid JWT', 'User does not exist')

    _app_ctx_stack.top.current_identity = identity
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号