class UnauthorizedError(Exception): ... def get_user(access_token: str, /, idp_client) -> dict[str, str]: """Gets the user attributes and metadata for a user.""" try: user = idp_client.get_user(AccessToken=access_token) except idp_client.exceptions.ClientError: raise UnauthorizedError() else: return {attr['Name']: attr['Value'] for attr in user['UserAttributes']}