-
Notifications
You must be signed in to change notification settings - Fork 566
401 Unauthorized when using service account app-only token to make API calls #599
Description
I started out getting the App-only token to ensure my app is authorized by the admin to silently perform actions across all users. I have been using the graph APIs for a lot of my use cases but the graph API(nor the outlook API) supports things like getting the current list of rules etc. The token has the permissions required to access EWS APIs.
I then decided to use EWS API as it mentioned it has support for InboxRules management. However it does not seem to accept the token I have from my app in azure AD.
However I get a 401 Unauthorized instead of the error your seeing.
Exception in thread "main" microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. The request failed. The remote server returned an error: (401)Unauthorized at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:74) at microsoft.exchange.webservices.data.core.request.GetInboxRulesRequest.execute(GetInboxRulesRequest.java:143) at microsoft.exchange.webservices.data.core.ExchangeService.getInboxRules(ExchangeService.java:3459) at com.paloaltonetworks.aperture.token.ExchangeTokenService.getRules(ExchangeTokenService.java:164) at com.paloaltonetworks.aperture.token.ExchangeTokenService.main(ExchangeTokenService.java:193) Caused by: microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. The remote server returned an error: (401)Unauthorized at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.validateAndEmitRequest(ServiceRequestBase.java:644) at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:62) ... 4 more Caused by: microsoft.exchange.webservices.data.core.exception.http.HttpErrorException: The remote server returned an error: (401)Unauthorized at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.getEwsHttpWebResponse(ServiceRequestBase.java:723) at microsoft.exchange.webservices.data.core.request.ServiceRequestBase.validateAndEmitRequest(ServiceRequestBase.java:639) ... 5 more
Is this because I cannot use the token I got for 'graph.microsoft.com' with the admin access? If not which token should I use and how do I go about getting it?