Is there a way to get user name and email with the token returned by oauth2 in Foundry?

Viewed 63

I am creating a company page (outside Foundry) which will use Foundry for authentication. I would like to show the name and email of the person who logged in in my website, is there a way to get it from the obtained token?

I checked the (internal) documentation pages for multipass and resource policy manager but could not see anything that would help.

1 Answers

You can call the user_info endpoint of multipass:

def get_user_info(self, hostname: str, auth_token: str) -> dict:
    """
    Returns the multipass user info
    Returns: dict, example:
    {
        'id': '1234bda5-686e-4fcb-ad52-d95e4281d99f',
        'username': '<username>',
        'attributes': {'multipass:email:primary': ['...'],...}
    }
    """
    response = requests.get(
        f"{hostname}/multipass/api/me", headers={
            "content-type": "application/json",
            "authorization": f"Bearer {auth_token}",
        }
    )
    response.raise_for_status()
    return response.json()
Related