I want to use adal4j lib for azure ad related tasks. It seems that it's not supporting local cache for access token, doesn't it? Is there any other libraries that provide that support?
2 Answers
Most of the open source libraries only provide protocol implementations. ADAL4J does not provide the cache support (unlike other ADALs), but abstracts out protocol details from a developer so that they can integrate with Azure AD. You could consider saving up the AuthenticationResult yourself and using the refresh token from the result when the access token expires. You can call acquireTokenUsingRefreshToken for that.
As @KanishkPanwar-MSFT said, ADAL4j does not support any cache mechanism for access token.
However, as I known, there is a guideline shows how to cache access token which be from the section "Cache Access Token" of the article Best Practices for OAuth 2.0 in Azure AD.
Cache Access Tokens
To minimize network calls from the client application and their associated latency, the client application should cache access tokens for the token lifetime that is specified in the OAuth 2.0 response. To determine the token lifetime, use either the expires_in or expires_on parameter values.
If a web API resource returns an invalid_token error code, this might indicate that the resource has determined that the token is expired. If the client and resource clock times are different (known as a "time skew"), the resource might consider the token to be expired before the token is cleared from the client cache. If this occurs, clear the token from the cache, even if it is still within its calculated lifetime.
Meanwhile, there is an article Caching access tokens in a multitenant application that I think you can refer to, which includes some sample code for .NET.