import requests


def get_token(username: str,
              pw: str,
              filehost: str = "securefileshare.wales.nhs.uk") -> dict:
    """
    Fetch Bearer token for securefileshare

    Parameters
    ----------
    username: str
    pw: str
    filehost: str

    Returns
    -------
    dict
        Dictionary. Access token under key "access_token"
    """
    endpoint = f"https://{filehost}/api/v1/token"
    data = {"grant_type": "password",
            "username": username,
            "password": pw}
    token = requests.post(endpoint,
                          data=data,
                          verify=False)
    assert token.status_code == 200, f"Request failed. Error code: {token.status_code}"
    json = token.json()
    token.close()
    return json