Search code examples
office365exchange-serverexchange-server-2007

Receive invalid_grant from Microsoft Exchange Server


I have a problem to send api to Exchange Server. I registered an app in Azure and added the "Office 365 Exchange Online" permissions into the api access role.

Next, I followed this document to get an app-only access token, and then sent GetItem EWS api to get an mail, but the server responses error with 401 Unauthorized.

x-ms-diagnostics: 2000008;"reason"=The token contains no permissions, or permissions can not be understood.";error_category="invalid_grant"

Is there permission settings in Office 365 I have to set up?


Solution

  • After I use JWT tool to see my access token, I found that the token doesn't have "Office 365 Exchange Online" permissions.

    The root cause is that while I was authorizing the app to use my Office 365 account , I haven't set "Office 365 Exchange Online" permissions to my app.

    Even thought I edited the permission setting soon after, the token is still no permission.

    Therefore, after modifying permission setting, we should re-auth and get a new app-only access token.