I am trying to access EWS using OAuth 2 but I am getting an error The remote server returned an error: (401)Unauthorized
I successfully received Access/Refresh Token
Here adding a token to the ExchangeService
ExchangeService service = new ExchangeService("Exchange2010_SP1");
service.getHttpHeaders().put("Authorization", "Bearer " + "some token");
service.setUrl("_serviceURI");
service.findFolders(WellKnownFolderName.Drafts, new FolderView(Integer.MAX_VALUE));
nowhere I got an error The remote server returned an error: (401)Unauthorized
what I am doing wrong here?
following is my authorize URL
https://login.microsoftonline.com/{tenant id}/oauth2/v2.0/authorize?
client_id=client_id
&response_type=code
&redirect_uri=https://localhost:80800/api/
&response_mode=query
&scope=openid offline_access https://outlook.office365.com/.default
&state=12345