Get Emails through ASPOSE for Office365 Users with MFA enabled

53 Views Asked by At

I'm building an application getting emails for Office365 users using ASPOSE.

My users have MFA enabled so I can't use ROPC like recommanded in Aspose documentation

Once I get my access token, I need it to refresh when it expires.

I searched for hours in Microsoft and Aspose documentation and I'm a bit lost.

Does someone went through the same issue?

Thanks

1

There are 1 best solutions below

0
On

Please refer to the following sections of Microsoft documentation:

MSAL maintains a token cache (or two caches for confidential client applications) and caches a token after it's been acquired. In many cases, attempting to silently get a token will acquire another token with more scopes based on a token in the cache. It's also capable of refreshing a token when it's getting close to expiration (as the token cache also contains a refresh token).

Thus, you should monitor the access token expiration or force a refresh after a certain time interval (e.g. 30 min):

AuthenticationResult result;
try
{
 // will handle expired Access Tokens by fetching new ones using the Refresh Token
 result = await AcquireTokenSilent(scopes).ExecuteAsync();
}
catch(MsalUiRequiredException ex)
{
 result = AcquireTokenXXXX(scopes, ..).WithXXX(…).ExecuteAsync();
}

Also, you can refer to the blog article explaining how to use modern authentication with Aspose.Email to connect to Microsoft365.