Search code examples
vb.netoauthtokenexchangewebservices

EWS Oauth login expires, have to login every time application starts


I am having problem in VB.Net code that connects to Mailbox using EWS. A mail account required 2F auth, 2F auth works but the problem is - EWS Oauth login expires, have to login every time application starts.

Using AcquireTokenSilentAsync, it doesn’t work 
authenticationresult = authenticationContext.AcquireTokenSilentAsync(serverName, clientID).Result
AcquireTokenAsync to authenticate
authenticationresult = authenticationContext.AcquireTokenAsync(serverName, clientID, clientAppUri, oPlatformParameters).Result

A VB.Net example that solves this will be helpful.


Solution

  • If you already have the access token, why do you need to recreate it every time instead of reusing authenticationresult.AccessToken?

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