Migrate ADAL TokenCache to MSAL TokenCache

Yinyin Qian 1 Reputation point
2021-12-09T09:15:19.743+00:00

Hi, we are migrating from ADAL library to MSAL library for a Windows service which runs in background.

In our current design, after user's first login, the TokenCache object in ADAL is serialized and save to a local file. When the machine reboots, the TokenCache is loaded and deserialized from the token cache file so that user don't need to re-login.

After migrating to MSAL, our expectation is that we can silently load the existing token cache file and transform the content to a format which can be consumed by MSAL. So that we don't need to let user re-login to get a new token cache for MSAL.

The question is that is this feasible? If yes, anything can be shared on this idea?

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
21,902 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Shweta Mathur 29,761 Reputation points Microsoft Employee
    2021-12-29T15:08:53.08+00:00

    Hi @Yinyin Qian ,

    Thanks for reaching out.

    No, Its not feasible to load the existing token cache of ADAL to MSAL as access token would not be the same to consumed by MSAL.

    ADAL uses Azure AD v1.0 authority in Azure ADAL and acquire token for resources while MSAL uses v2.0 authority and acquire token for scopes so claims would differ for both the libraries.

    Also, The Microsoft identity platform endpoint issues a smaller set of claims in its tokens by default to keep payloads small. If your application a dependency on a particular claim which was in v1.0 token of ADAL, then you need to use optional claims features to include that claim.

    So, even though you were able to load the token silently in some way it would not be consumed by MSAL.
    You will require one time user’s login to get the fresh access token for MSAL and then cache the token and use token serialization to acquire token silently further.

    Refer token cache serialization in MSAL.NET to handle the token in MSAL.

    Thanks,
    Shweta

    ----------------------------------------

    Please remember to "Accept Answer" if answer helped you.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.