Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

Jmprieur/fix msal deserialize regression #1229

Merged
merged 2 commits into from
Aug 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,20 @@ public static void SetBeforeWrite(this TokenCache tokencache, TokenCache.TokenCa
/// <param name="tokenCache">Token cache to deserialize (to fill-in from the state)</param>
/// <param name="unifiedState">Array of bytes containing serialized Msal cache data</param>
/// <remarks>
/// <paramref name="unifiedState"/>Is a Json blob containing access tokens, refresh tokens, id tokens and accounts information
/// <paramref name="unifiedState"/>Is a Json blob containing access tokens, refresh tokens, id tokens and accounts information.
/// If it's <c>null</c>, then this method won't do anything (this is the same behavior as MSAL 1.x)
/// </remarks>
public static void Deserialize(this TokenCache tokenCache, byte[] unifiedState)
{
lock (tokenCache.LockObject)
// Only deserialize if there is something to deserialize (like in MSAL 1.x)
if (unifiedState != null)
{
RequestContext requestContext = new RequestContext(new MsalLogger(Guid.Empty, null));
lock (tokenCache.LockObject)
{
RequestContext requestContext = new RequestContext(new MsalLogger(Guid.Empty, null));

TokenCacheSerializeHelper.DeserializeUnifiedCache(tokenCache.tokenCacheAccessor, unifiedState, requestContext);
TokenCacheSerializeHelper.DeserializeUnifiedCache(tokenCache.tokenCacheAccessor, unifiedState, requestContext);
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions msal/tests/Test.MSAL.NET.Unit/CacheTests/TokenCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,9 @@ public void SerializeDeserializeCacheTest()
ClientId = TestConstants.ClientId
};

// Backward compatibility with MSAL 1.x, this should not throw
cache.Deserialize(null);

MsalTokenResponse response = new MsalTokenResponse();
response.IdToken = MockHelpers.CreateIdToken(TestConstants.UniqueId, TestConstants.DisplayableId);
response.ClientInfo = MockHelpers.CreateClientInfo();
Expand Down