My Office add-in (which runs in Outlook) uses the OfficeJS library to get a callback token for authentication against Exchange:
Office.context.mailbox.getCallbackTokenAsync(...);
The token is sent to our server together with some message/attachment IDs and the server will attempt to connect to Exchange to retrieve said mail attachment. I use the EWS java API library for this. I am getting an Unauthorized 401 HTTP error back from Exchange when trying to bind to an EmailMessage:
ExchangeService exchangeService = new ExchangeService();
exchangeService.getHttpHeaders().put("Authorization", "Bearer " + callbackToken);
exchangeService.setUrl(new URI(ewsUrl));
EmailMessage mailMessage = EmailMessage.bind(exchangeService, new ItemId(mailMessageId));
When tested against Office 365 it all works flawlessly. However, when running this at a client I get the HTTP 401 response. The client runs Exchange 2013 on-premise. Does Exchange 2013 on-premise even support token authentication? Is there anything that needs to be done to enable this on that version of Exchange?