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

Commit

Permalink
Merge pull request #53 from Azure-Samples/jmprieur/updateToMsal2
Browse files Browse the repository at this point in the history
Update for MSAL 2.
  • Loading branch information
parakhj authored Aug 29, 2018
2 parents 85effe8 + 77a37d6 commit 03e2f42
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 4 additions & 1 deletion WebApp-OpenIDConnect-DotNet/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ public async Task<IActionResult> Api()
var scope = AzureAdB2COptions.ApiScopes.Split(' ');
string signedInUserID = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
TokenCache userTokenCache = new MSALSessionCache(signedInUserID, this.HttpContext).GetMsalCacheInstance();

ConfidentialClientApplication cca = new ConfidentialClientApplication(AzureAdB2COptions.ClientId, AzureAdB2COptions.Authority, AzureAdB2COptions.RedirectUri, new ClientCredential(AzureAdB2COptions.ClientSecret), userTokenCache, null);

AuthenticationResult result = await cca.AcquireTokenSilentAsync(scope, cca.Users.FirstOrDefault(), AzureAdB2COptions.Authority, false);

var accounts = await cca.GetAccountsAsync();
AuthenticationResult result = await cca.AcquireTokenSilentAsync(scope, accounts.FirstOrDefault(), AzureAdB2COptions.Authority, false);

HttpClient client = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, AzureAdB2COptions.ApiUrl);
Expand Down
6 changes: 5 additions & 1 deletion WebApp-OpenIDConnect-DotNet/Models/MSALSessionCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ public string ReadUserStateValue()
public void Load()
{
SessionLock.EnterReadLock();
cache.Deserialize(httpContext.Session.Get(CacheId));
byte[] blob = httpContext.Session.Get(CacheId);
if (blob !=null)
{
cache.Deserialize(blob);
}
SessionLock.ExitReadLock();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RootNamespace>WebApp_OpenIDConnect_DotNet</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Identity.Client" Version="1.1.0-preview" />
<PackageReference Include="Microsoft.Identity.Client" Version="2.0.0-preview" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="2.0.0" />
Expand Down

0 comments on commit 03e2f42

Please sign in to comment.