def auth_header(db, name):
    """Return header with user's API authorization token."""
    user = find_user(db, name)
    if user is None:
        raise KeyError(f"No such user: {name}")
    token = user.new_api_token()
    return {'Authorization': f'token {token}'}
Return header with user's API authorization token.
jupyterhub/tests/utils.py