authentication_service.py 文件源码

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

项目:tasking-manager 作者: hotosm 项目源码 文件源码
def verify_token(token):
    """ Verify the supplied token and check user role is correct for the requested resource"""

    if not token:
        current_app.logger.debug(f'Token not supplied {request.base_url}')
        return False

    try:
        decoded_token = base64.b64decode(token).decode('utf-8')
    except UnicodeDecodeError:
        current_app.logger.debug(f'Unable to decode token {request.base_url}')
        return False  # Can't decode token, so fail login

    valid_token, user_id = AuthenticationService.is_valid_token(decoded_token, 604800)
    if not valid_token:
        current_app.logger.debug(f'Token not valid {request.base_url}')
        return False

    if tm.is_pm_only_resource:
        if not UserService.is_user_a_project_manager(user_id):
            current_app.logger.debug(f'User {user_id} is not a PM {request.base_url}')
            return False

    tm.authenticated_user_id = user_id  # Set the user ID on the decorator as a convenience
    return True  # All tests passed token is good for the requested resource
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号