Authenticate and fetch EWS data using OAuth token #579
Description
I am trying to build an android app using EWS-java-api to fetch EWS data with an oAuth2 token for office365 users using active directory authentication lib for android. similar to what is shown in this article for .net
Below is the code:
// Code to acquire token after registering the native application in Azure active directory
authenticationContext.acquireToken(<activity context>, "<resource id: copied from the manifest file tag <resourceAppId> of Azure active directory after adding permission>", "<Application id of the registered app in AAD>", "<Application Redirect URI>", email, PromptBehavior.Always, "", AuthenticationCallback);
//We receive AuthenticationResult object containing authentication token in AuthenticationCallback onSuccess method and then call an async task to fetch EWS data
ExchangeService exchangeService = new ExchangeService(); exchangeService.setTraceEnabled(true); exchangeService.getHttpHeaders().put("Authorization", "Bearer " + mAuthenticationResult.getAccessToken()); exchangeService.setUrl(URI.create("https://outlook.office365.com/EWS/Exchange.asmx"));
I am able to get oAuth token, but i am not able to receive exchange data, it gives me unauthorised and forbidden access when fetching data using below code.
CalendarFolder cf = CalendarFolder.bind(service, WellKnownFolderName.Calendar); findResults = cf.findAppointments(new CalendarView(startDate, endDate));
Also, i am not sure about the configuration i am setting up in azure portal. It would be great if you can tell how to setup Azure AD application for fetching EWS data via oAuth authentication in android.