import requests


def auth(gurl, beid, wskey):
    """ Formats the provided TDX information into the appropriate format,
        uses Requests to get a bearer token, then returns HTTP headers.

    Args:
        gurl (str): the API URL of the TeamDynamix environment
        beid (str): TeamDynamix environment BEID
        wskey (str): TeamDynamix environment Web Services Key

    Returns:
        headers (str): A string including the content-type and bearer token, used
            for future API calls to TDX; bearer is only valid for this session
    """

    data = {
        "BEID": beid,
        "WebServicesKey": wskey
    }

    bearer = requests.post(
        url = gurl + "/api/auth/loginadmin",
        json = data
    )

    token = str(bearer.content, "utf-8")

    headers = {
        "Content-Type": "application/json",
        "Authorization": "Bearer " + token
    }
    return headers