0

I have been using the ews-android-api in my android application to get the calendar events etc.. According to the docs, the basic authentication will be deprecated on the coming October 2020. I believe the basic authentication have been using in my android application, So how can I use modern authentication instead of basic authentication in my application to continue using the ews-android-api in my projects even after October.

Looking forward to your suggestions and support.

The sample code used for login in my android application

private void loginEws(){
 
       ExchangeUser user = new ExchangeUser(mUsername, mPassword, mExchangeServerUrl, mMailboxEmail);
       ExchangeHelper helper = new ExchangeHelper(user);
       helper.login();
                 
   }
  public void login() throws Exception {
        ExchangeService service = createService();
        Mailbox mailbox = new Mailbox(user.getMailbox());
        FolderId folderId = new FolderId(WellKnownFolderName.Calendar, mailbox);
        CalendarFolder folder = CalendarFolder.bind(service, folderId);
    }


 private ExchangeService createService() {
        try {
            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
            ExchangeCredentials credentials = new WebCredentials(user.getUsername(), user.getPassword());
            service.setUrl(new URI(user.getServerUrl()));
            service.setCredentials(credentials);
            return service;
        } catch (URISyntaxException e) {
            e.printStackTrace();
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
Arun S
  • 1
  • 2
  • Can you give a link to the doc where you read basic authentication is deprecated? – Shivam Pokhriyal Jun 25 '20 at 06:51
  • @ShivamPokhriyal Please go through this link https://techcommunity.microsoft.com/t5/exchange-team-blog/upcoming-changes-to-exchange-web-services-ews-api-for-office-365/ba-p/608055 – Arun S Jun 25 '20 at 20:04

1 Answers1

0

See the docs: https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-authenticate-an-ews-application-by-using-oauth

We have fixed this problem:

  1. Get token with scope - https://outlook.office365.com/EWS.AccessAsUser.All
  2. Add the token to headers:
var service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
service.setUrl(URI.create("https://outlook.office365.com/ews/exchange.asmx"));
service.getHttpHeaders().put("Authorization", "Bearer " + token);

That's all, no any other headers, just valid token and correct service config.