Hello,
I'm attempting to read the emails of a user who's part of my Azure Active Directory as part of an automation test. I have to preface I'm not using the MSAL library as I want the implementation to be as lightweight as possible.
I've authenticated and gotten a token fine by using ClientCredentials (tenant id, client id and secret) and by using jwt.ms, I've verified that the token has the correct permissions "roles": [ "User.Read.All", "Mail.Read" ]and hasn't expired.
The issue I'm having is I can get a list of the users by doing a get("https://graph.microsoft.com/v1.0/users", headers=self._headers()" However as soon as I try to get the e-mails with get(f"https://graph.microsoft.com/v1.0/users/{user_id}/messages", headers=mail_headers) It will always return a 400 AuthenticationError, Error authenticating with resource.
This is def _headers(self): return {"Authorization": f"Bearer {self.azure_client.token"}", "Host":"graph.microsoft.com"}which just returns the token in a dictionary for the requests rather than typing it out constantly and mail_headers just appends "Prefer":"outlook.body-text"to the headers as per the documentation.
Any advice or things I should check would be greatly appreciated.
Thanks in advance,
Brennan