Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit 6dbb7e8

Browse files
authored
Update to msal 431 (#79)
1 parent 23f529b commit 6dbb7e8

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

WebApp-OpenIDConnect-DotNet/Models/StaticCache.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,29 @@
22

33
using System.Threading;
44
using Microsoft.AspNetCore.Http;
5-
using Microsoft.Extensions.Caching.Memory;
65
using System.Collections.Generic;
76

87
namespace WebApp_OpenIDConnect_DotNet.Models
98
{
9+
/// <summary>
10+
/// This implementation is just for demo purposes and does not scale. For better cache implementations see
11+
/// https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/tree/master/2-WebApp-graph-user/2-1-Call-MSGraph
12+
/// </summary>
1013
public class MSALStaticCache
1114
{
1215
private static Dictionary<string, byte[]> staticCache = new Dictionary<string, byte[]>();
1316

1417
private static ReaderWriterLockSlim SessionLock = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion);
15-
string UserId = string.Empty;
16-
string CacheId = string.Empty;
18+
private readonly string userId = string.Empty;
19+
private readonly string cacheId = string.Empty;
1720
private readonly HttpContext httpContext = null;
1821
private ITokenCache cache;
1922

2023
public MSALStaticCache(string userId, HttpContext httpcontext)
2124
{
2225
// not object, we want the SUB
23-
UserId = userId;
24-
CacheId = UserId + "_TokenCache";
26+
this.userId = userId;
27+
cacheId = this.userId + "_TokenCache";
2528
httpContext = httpcontext;
2629
}
2730

@@ -36,7 +39,7 @@ public ITokenCache EnablePersistence(ITokenCache cache)
3639
public void Load(TokenCacheNotificationArgs args)
3740
{
3841
SessionLock.EnterReadLock();
39-
byte[] blob = staticCache.ContainsKey(CacheId) ? staticCache[CacheId] : null ;
42+
byte[] blob = staticCache.ContainsKey(cacheId) ? staticCache[cacheId] : null ;
4043
if(blob != null)
4144
{
4245
args.TokenCache.DeserializeMsalV3(blob);
@@ -49,7 +52,7 @@ public void Persist(TokenCacheNotificationArgs args)
4952
SessionLock.EnterWriteLock();
5053

5154
// Reflect changes in the persistent store
52-
staticCache[CacheId] = args.TokenCache.SerializeMsalV3();
55+
staticCache[cacheId] = args.TokenCache.SerializeMsalV3();
5356
SessionLock.ExitWriteLock();
5457
}
5558

WebApp-OpenIDConnect-DotNet/WebApp-OpenIDConnect-DotNet.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<RootNamespace>WebApp_OpenIDConnect_DotNet</RootNamespace>
55
</PropertyGroup>
66
<ItemGroup>
7-
<PackageReference Include="Microsoft.Identity.Client" Version="4.3.0" />
7+
<PackageReference Include="Microsoft.Identity.Client" Version="4.3.1" />
88
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
99
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.2.0" />
1010
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="2.2.0" />

0 commit comments

Comments
 (0)