I've hit a weird situation where my graphclient has permissions to set presence for a user, but aren't allowed to read presence from the same user.
I have read/readwrite permissions added in the Azure portal, for the app registration.
There's no further explanation in the error:
{"error":{"code":"Forbidden","message":"","innerError":{"request-id":"ddc6fc84-0edc-4fc9-b606-3c0de6d6067c","date":"2023-07-03T06:34:02","client-request-id":"ddc6fc84-0edc-4fc9-b606-3c0de6d6067c"}}}
And I attempt to read presence like so:
var presence = await graphClient.Users[userId].Presence.Request().GetAsync();
When I set presence it works, and I do that like so:
await graphClient.Users[userId].Presence
.SetPresence(availability, activity, _clientDetails.ClientId, new Duration("PT1H")).Request()
.PostAsync();
Here are my permissions:
Am I missing something obvious, or have anyone else experienced similar issues?
It appears that reading presence is not intended to work when using application permissions. Which makes the Presence.Read.All application permission a bit misleading.
Answered here https://learn.microsoft.com/en-us/answers/questions/1323478/get-presence-returns-forbiddne-set-presence-works And confirmed that the code from my question works when i generate a token by logging in, instead of creating it using the tenant Id.
Hopefully this answer can be replaced sometime, when it is possible to read presence using the application permission, but for now that's not the case.