问题
I am using ADAL's (Microsoft.IdentityModel.Clients.ActiveDirectory v4.3.0) AuthenticationContext.AcquireTokenAsync
to acquire a bearer token with a ClientCredential
.
I am creating a new AuthenticationContext
to acquire a token for each request. Is that thread-safe? Or do I have to lock the call to AcquireTokenAsync
with a static SemaphoreSlim
?
I am asking because according to http://www.cloudidentity.com/blog/2013/10/01/getting-acquainted-with-adals-token-cache/ the method uses a static token cache which is not thread-safe, but the article is quite old and I haven't found any more up-to-date information.
回答1:
ADAL.NET v4.3 can not at this point in time be considered thread safe. We are working towards this with MSAL v2+.
来源:https://stackoverflow.com/questions/52992009/is-acquiretokenasync-thread-safe