title: The remote server returned an error: (421) -Getting this error when trying to access Office 365 mailbox
body: <p>I have created a standalone netbeans java 8.0 application which uses EWS to connect to Office 365 mailbox. I have registered the same in the Azure Directory.
  Currently using basic authentication ,I can download the mails from the Office 365 mailbox and check the attachements. But the momment i change it to xoauth method using access token i get above mentioned error (The remote server returned an error: (421)). Can you please help me out with this.
  I have used below code.</p>
  <pre><code>IClientCredential credential = ClientCredentialFactory.createFromSecret(CLIENT_SECRET);
              ConfidentialClientApplication app = ConfidentialClientApplication
                      .builder(PUBLIC_CLIENT_ID, credential)
                      .authority(AUTHORITY)
                      .build();
   
  Set&lt;String&gt; scopes = new HashSet&lt;String&gt;();
  scopes.add(&quot;api://&quot;+PUBLIC_CLIENT_ID&quot;/.default&quot;);
  
   ClientCredentialParameters clientCredentialParameters = ClientCredentialParameters.builder(scopes).build();
               CompletableFuture&lt;IAuthenticationResult&gt; future = app.acquireToken(clientCredentialParameters);
  
   ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
   service.setUrl(new URI(&quot;https://outlook.office365.com/EWS/exchange.asmx&quot;));
  
   BearerAccessToken bat = new BearerAccessToken(future.get().accessToken());
  ExchangeCredentials credentials = new TokenCredentials(bat.getValue());
  EnumSet&lt;TraceFlags&gt; es = EnumSet.of(TraceFlags.EwsRequest, TraceFlags.EwsRequestHttpHeaders, TraceFlags.EwsResponse, TraceFlags.EwsResponseHttpHeaders,TraceFlags.DebugMessage);
  
   service.setCredentials(credentials);
   service.setTraceEnabled(true);
   service.setTraceFlags(es);
  
  FindItemsResults findResults = service.findItems(WellKnownFolderName.Inbox, itemview);
  </code></pre>
  <p>The last last step above give me the error.
  I am new to this msal4j and EWS . Can you please help me out with this. I need to access a office 365 mailbox for example: abc@abc.biz</p>