The support for ADAL ends on June 30, 2022 and Microsoft recommends migrating applications to MSAL.
During migration, I encountered a difficulty migrating a code that accesses Data Lake Storage from ADAL to MSAL. My almost-working attempt is:
// Before migration (authenticate using obsolete ADAL)
ClientCredential clientCredential = new ClientCredential(clientId, clientSecret);
ServiceClientCredentials credentials = await ApplicationTokenProvider.LoginSilentAsync(tenantId, clientCredential);
var adlsClient = AdlsClient.CreateClient(dataLakeStoreName, serviceCredentials)
// After migration (authenticate using newer MSAL)
var clientApplication = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithClientSecret(clientSecrret)
.WithAuthority(new Uri($"https://login.microsoftonline.com/{tenantId}"))
.Build();
AuthenticationResult credentials = await (new[] { $"https://datalake.azure.net/.default" })
.ExecuteAsync();
// We no longer have ServiceClientCredentials object, so the only overload left is the one that accepts a bearer token as a string:
var adlsClient = AdlsClient
.CreateClient(dataLakeStoreName, $"{credentials.TokenType} {credentials.AccessToken}");
The above MSAL code works for a while, but with ServiceClientCredentials gone, we lost the object responsible for refreshing a token. So, when the token expires, adlsClient now stops working.
Is there any simple way to create a ServiceClientCredentials with MSAL?
Or do we need to code the logic that refreshes the token ourselves when we migrate to MSAL?