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

Commit dff48f4

Browse files
authored
Merge pull request #62 from Azure-Samples/jennyf/msalv2.7
update to 2.7
2 parents 5a500ab + 4972658 commit dff48f4

File tree

5 files changed

+23
-25
lines changed

5 files changed

+23
-25
lines changed

WebApp-OpenIDConnect-DotNet/Controllers/HomeController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public async Task<IActionResult> Api()
4747
TokenCache userTokenCache = new MSALSessionCache(signedInUserID, this.HttpContext).GetMsalCacheInstance();
4848
ConfidentialClientApplication cca = new ConfidentialClientApplication(AzureAdB2COptions.ClientId, AzureAdB2COptions.Authority, AzureAdB2COptions.RedirectUri, new ClientCredential(AzureAdB2COptions.ClientSecret), userTokenCache, null);
4949

50-
AuthenticationResult result = await cca.AcquireTokenSilentAsync(scope, cca.Users.FirstOrDefault(), AzureAdB2COptions.Authority, false);
50+
var accounts = await cca.GetAccountsAsync();
51+
AuthenticationResult result = await cca.AcquireTokenSilentAsync(scope, accounts.FirstOrDefault(), AzureAdB2COptions.Authority, false);
5152

5253
HttpClient client = new HttpClient();
5354
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, AzureAdB2COptions.ApiUrl);

WebApp-OpenIDConnect-DotNet/Models/MSALSessionCache.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,18 @@ public string ReadUserStateValue()
4848
public void Load()
4949
{
5050
SessionLock.EnterReadLock();
51-
cache.Deserialize(httpContext.Session.Get(CacheId));
51+
byte[] blob = httpContext.Session.Get(CacheId);
52+
if(blob != null)
53+
{
54+
cache.Deserialize(blob);
55+
}
5256
SessionLock.ExitReadLock();
5357
}
5458

5559
public void Persist()
5660
{
5761
SessionLock.EnterWriteLock();
5862

59-
// Optimistically set HasStateChanged to false. We need to do it early to avoid losing changes made by a concurrent thread.
60-
cache.HasStateChanged = false;
61-
6263
// Reflect changes in the persistent store
6364
httpContext.Session.Set(CacheId, cache.Serialize());
6465
SessionLock.ExitWriteLock();
@@ -75,7 +76,7 @@ void BeforeAccessNotification(TokenCacheNotificationArgs args)
7576
void AfterAccessNotification(TokenCacheNotificationArgs args)
7677
{
7778
// if the access operation resulted in a cache update
78-
if (cache.HasStateChanged)
79+
if (args.HasStateChanged)
7980
{
8081
Persist();
8182
}

WebApp-OpenIDConnect-DotNet/Startup.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
1+
using Microsoft.AspNetCore.Authentication.Cookies;
2+
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
53
using Microsoft.AspNetCore.Builder;
64
using Microsoft.AspNetCore.Hosting;
5+
using Microsoft.AspNetCore.Http;
76
using Microsoft.Extensions.Configuration;
87
using Microsoft.Extensions.DependencyInjection;
98
using Microsoft.Extensions.Logging;
10-
using Microsoft.AspNetCore.Authentication.Cookies;
11-
using Microsoft.Extensions.Options;
12-
using Microsoft.AspNetCore.Http;
13-
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
9+
using System;
1410

1511
namespace WebApp_OpenIDConnect_DotNet
1612
{
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFramework>netcoreapp2.0</TargetFramework>
3+
<TargetFramework>netcoreapp2.2</TargetFramework>
44
<RootNamespace>WebApp_OpenIDConnect_DotNet</RootNamespace>
55
</PropertyGroup>
66
<ItemGroup>
7-
<PackageReference Include="Microsoft.Identity.Client" Version="1.1.0-preview" />
8-
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" />
9-
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.0.0" />
10-
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="2.0.0" />
11-
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0" />
12-
<PackageReference Include="Microsoft.AspNetCore.Session" Version="2.0.0" />
13-
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.0" />
14-
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0" />
15-
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.0" />
7+
<PackageReference Include="Microsoft.Identity.Client" Version="2.7.0" />
8+
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
9+
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.2.0" />
10+
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="2.2.0" />
11+
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
12+
<PackageReference Include="Microsoft.AspNetCore.Session" Version="2.2.0" />
13+
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" />
14+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.2.0" />
15+
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
1616
</ItemGroup>
1717
</Project>

WebApp-OpenIDConnect-DotNet/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"RedirectUri": "http://localhost:5000/signin-oidc",
1010
"ClientSecret" : "v0WzLXB(uITV5*Aq",
1111
"ApiUrl": "https://fabrikamb2chello.azurewebsites.net/hello",
12-
"ApiScopes": "https://fabrikamb2c.onmicrosoft.com/demoapi/demo.read"
12+
"ApiScopes": "https://fabrikamb2c.onmicrosoft.com/helloapi/demo.read"
1313
}
1414
},
1515
"Logging": {

0 commit comments

Comments
 (0)