Skip to content

Commit 46516ca

Browse files
authored
Update to MSAL 4.3.1 (#59)
* Update to MSAL 4.3.1 * 431 and remove non-used cache
1 parent 1373293 commit 46516ca

File tree

5 files changed

+15
-237
lines changed

5 files changed

+15
-237
lines changed

TaskWebApp/TaskWebApp.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
<HintPath>..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll</HintPath>
5353
</Reference>
5454
<Reference Include="Microsoft.CSharp" />
55-
<Reference Include="Microsoft.Identity.Client, Version=3.0.8.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae, processorArchitecture=MSIL">
56-
<HintPath>..\packages\Microsoft.Identity.Client.3.0.8\lib\net45\Microsoft.Identity.Client.dll</HintPath>
55+
<Reference Include="Microsoft.Identity.Client, Version=4.3.1.0, Culture=neutral, PublicKeyToken=0a613f4dd989e8ae, processorArchitecture=MSIL">
56+
<HintPath>..\packages\Microsoft.Identity.Client.4.3.1\lib\net45\Microsoft.Identity.Client.dll</HintPath>
5757
</Reference>
5858
<Reference Include="Microsoft.IdentityModel.JsonWebTokens, Version=5.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
5959
<HintPath>..\packages\Microsoft.IdentityModel.JsonWebTokens.5.4.0\lib\net451\Microsoft.IdentityModel.JsonWebTokens.dll</HintPath>
@@ -187,7 +187,6 @@
187187
<Compile Include="Utils\Globals.cs" />
188188
<Compile Include="Utils\MsalAppBuilder.cs" />
189189
<Compile Include="Utils\MSALPerUserMemoryTokenCache.cs" />
190-
<Compile Include="Utils\MSALPerUserSessionTokenCache.cs" />
191190
</ItemGroup>
192191
<ItemGroup>
193192
<Content Include="Content\bootstrap.css" />

TaskWebApp/Utils/MSALPerUserMemoryTokenCache.cs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ public class MSALPerUserMemoryTokenCache
4141
/// </summary>
4242
private readonly DateTimeOffset cacheDuration = DateTimeOffset.Now.AddHours(48);
4343

44-
/// <summary>
45-
/// The internal handle to the client's instance of the Cache
46-
/// </summary>
47-
private ITokenCache UserTokenCache;
48-
4944
/// <summary>
5045
/// Once the user signes in, this will not be null and can be ontained via a call to Thread.CurrentPrincipal
5146
/// </summary>
@@ -77,18 +72,15 @@ private void Initialize(ITokenCache tokenCache, ClaimsPrincipal user)
7772
{
7873
this.SignedInUser = user;
7974

80-
this.UserTokenCache = tokenCache;
81-
this.UserTokenCache.SetBeforeAccess(this.UserTokenCacheBeforeAccessNotification);
82-
this.UserTokenCache.SetAfterAccess(this.UserTokenCacheAfterAccessNotification);
83-
this.UserTokenCache.SetBeforeWrite(this.UserTokenCacheBeforeWriteNotification);
75+
tokenCache.SetBeforeAccess(this.UserTokenCacheBeforeAccessNotification);
76+
tokenCache.SetAfterAccess(this.UserTokenCacheAfterAccessNotification);
77+
tokenCache.SetBeforeWrite(this.UserTokenCacheBeforeWriteNotification);
8478

8579
if (this.SignedInUser == null)
8680
{
8781
// No users signed in yet, so we return
8882
return;
8983
}
90-
91-
this.LoadUserTokenCacheFromMemory();
9284
}
9385

9486
/// <summary>
@@ -107,7 +99,7 @@ internal string GetMsalAccountId()
10799
/// <summary>
108100
/// Loads the user token cache from memory.
109101
/// </summary>
110-
private void LoadUserTokenCacheFromMemory()
102+
private void LoadUserTokenCacheFromMemory(ITokenCacheSerializer tokenCache)
111103
{
112104
string cacheKey = this.GetMsalAccountId();
113105

@@ -116,21 +108,21 @@ private void LoadUserTokenCacheFromMemory()
116108

117109
// Ideally, methods that load and persist should be thread safe. MemoryCache.Get() is thread safe.
118110
byte[] tokenCacheBytes = (byte[])this.memoryCache.Get(this.GetMsalAccountId());
119-
this.UserTokenCache.DeserializeMsalV3(tokenCacheBytes);
111+
tokenCache.DeserializeMsalV3(tokenCacheBytes);
120112
}
121113

122114
/// <summary>
123115
/// Persists the user token blob to the memoryCache.
124116
/// </summary>
125-
private void PersistUserTokenCache()
117+
private void PersistUserTokenCache(ITokenCacheSerializer tokenCache)
126118
{
127119
string cacheKey = this.GetMsalAccountId();
128120

129121
if (string.IsNullOrWhiteSpace(cacheKey))
130122
return;
131123

132124
// Ideally, methods that load and persist should be thread safe.MemoryCache.Get() is thread safe.
133-
this.memoryCache.Set(this.GetMsalAccountId(), this.UserTokenCache.SerializeMsalV3(), this.cacheDuration);
125+
this.memoryCache.Set(this.GetMsalAccountId(), tokenCache.SerializeMsalV3(), this.cacheDuration);
134126
}
135127

136128
/// <summary>
@@ -139,9 +131,6 @@ private void PersistUserTokenCache()
139131
public void Clear()
140132
{
141133
this.memoryCache.Remove(this.GetMsalAccountId());
142-
143-
// Nulls the currently deserialized instance
144-
this.LoadUserTokenCacheFromMemory();
145134
}
146135

147136
/// <summary>
@@ -155,7 +144,7 @@ private void UserTokenCacheAfterAccessNotification(TokenCacheNotificationArgs ar
155144
// if the access operation resulted in a cache update
156145
if (args.HasStateChanged)
157146
{
158-
this.PersistUserTokenCache();
147+
this.PersistUserTokenCache(args.TokenCache);
159148
}
160149
}
161150

@@ -165,7 +154,7 @@ private void UserTokenCacheAfterAccessNotification(TokenCacheNotificationArgs ar
165154
/// <param name="args">Contains parameters used by the MSAL call accessing the cache.</param>
166155
private void UserTokenCacheBeforeAccessNotification(TokenCacheNotificationArgs args)
167156
{
168-
this.LoadUserTokenCacheFromMemory();
157+
this.LoadUserTokenCacheFromMemory(args.TokenCache);
169158
}
170159

171160
/// <summary>

TaskWebApp/Utils/MSALPerUserSessionTokenCache.cs

Lines changed: 0 additions & 210 deletions
This file was deleted.

TaskWebApp/Utils/MsalAppBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ public static async Task ClearUserTokenCache()
7676
//Remove the users from the MSAL's internal cache
7777
await clientapp.RemoveAsync(account);
7878
}
79+
userTokenCache.Clear();
7980

80-
userTokenCache.Clear();
81-
}
82-
}
81+
}
82+
}
8383
}

TaskWebApp/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.7" targetFramework="net461" />
1010
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.7" targetFramework="net461" />
1111
<package id="Microsoft.AspNet.WebPages" version="3.2.7" targetFramework="net451" />
12-
<package id="Microsoft.Identity.Client" version="3.0.8" targetFramework="net451" />
12+
<package id="Microsoft.Identity.Client" version="4.3.1" targetFramework="net451" />
1313
<package id="Microsoft.IdentityModel.JsonWebTokens" version="5.4.0" targetFramework="net451" />
1414
<package id="Microsoft.IdentityModel.Logging" version="5.4.0" targetFramework="net451" />
1515
<package id="Microsoft.IdentityModel.Protocols" version="5.4.0" targetFramework="net451" />

0 commit comments

Comments
 (0)