ms-teams-cli icon indicating copy to clipboard operation
ms-teams-cli copied to clipboard

A 403 says nothing about which permission the token is missing

Open aberoham opened this issue 3 months ago • 0 comments

presence set without Presence.ReadWrite returns:

{"code":"PERMISSION_DENIED","message":"Permission denied: {\"error\":{\"code\":\"Forbidden\",\"message\":\"\", ...}}"}

Graph sends Forbidden with an empty message string, so the body says nothing about what is missing. The failure is indistinguishable from a genuine authorization refusal, a policy block, or a wrong resource. The only way to find out is to go and read teams auth status and compare the scope list against the operation by hand — which is exactly what the investigation behind #70 had to do.

The CLI already holds the answer. The access token carries its own scp claim (delegated) or roles (app-only), and TokenClaims already parses both (src/auth/token.rs:41-43). Printing them turns "Forbidden" into a list to check the operation against.

There is precedent in the codebase: GraphClient::auth_error_message (src/api/client.rs) already appends an audience hint to a 401.

Three places turn a 403 into an error and none of them add anything:

  • src/api/client.rs:65 (error_for_status)
  • src/api/client.rs:469 (request_with_retry)
  • src/api/client.rs:579 (request_with_retry_no_content)

Suggested fix: a permission_denied_message mirroring the 401 hint. An opaque token yields no claims and should get no hint rather than a guess.

aberoham avatar Aug 28 '26 15:08 aberoham