Skip to content

Commit

Permalink
Merge pull request #3 from nicotravassos/master
Browse files Browse the repository at this point in the history
⬆️ Microsoft.Identity.Client@2.7.0 and  Fix obsoletion warnings
  • Loading branch information
mkeymolen committed Feb 8, 2019
2 parents 24f6ead + 5a20997 commit 5c447f8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ public void AddDefaultHeaders(IDictionary<string,string> defaultHeaders)

private async Task<AuthenticationResult> GetToken()
{
return await _confidentialClientApplication.AcquireTokenSilentAsync(_azureAdB2COptions.Scopes, _confidentialClientApplication.Users.FirstOrDefault(), _azureAdB2COptions.Authority, false);
var accounts = await _confidentialClientApplication.GetAccountsAsync();
return await _confidentialClientApplication.AcquireTokenSilentAsync(_azureAdB2COptions.Scopes,
accounts.FirstOrDefault(), _azureAdB2COptions.Authority, false);
}

private void ValidateOptions(IOptions<AzureAdB2COptions> options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.2" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.0.2" />
<PackageReference Include="Microsoft.Identity.Client" Version="1.1.2-preview0008" />
<PackageReference Include="Microsoft.Identity.Client" Version="2.7.0" />
<PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="3.19.4" />
</ItemGroup>

Expand Down
15 changes: 5 additions & 10 deletions src/Hexiron.Azure.ActiveDirectory/Models/MSALSessionCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,37 +44,32 @@ public string ReadUserStateValue()
public void Load()
{
s_sessionLock.EnterReadLock();
cache.Deserialize(_httpContext.Session.Get(_cacheId));
var blob = _httpContext.Session.Get(_cacheId);
if (blob != null) cache.Deserialize(blob);
s_sessionLock.ExitReadLock();
}

public void Persist()
{
s_sessionLock.EnterWriteLock();

// Optimistically set HasStateChanged to false. We need to do it early to avoid losing changes made by a concurrent thread.
cache.HasStateChanged = false;

// Reflect changes in the persistent store
_httpContext.Session.Set(_cacheId, cache.Serialize());
s_sessionLock.ExitWriteLock();
}

// Triggered right before MSAL needs to access the cache.
// Reload the cache from the persistent store in case it changed since the last access.
void BeforeAccessNotification(TokenCacheNotificationArgs args)
private void BeforeAccessNotification(TokenCacheNotificationArgs args)
{
Load();
}

// Triggered right after MSAL accessed the cache.
void AfterAccessNotification(TokenCacheNotificationArgs args)
private void AfterAccessNotification(TokenCacheNotificationArgs args)
{
// if the access operation resulted in a cache update
if (cache.HasStateChanged)
{
Persist();
}
if (args.HasStateChanged) Persist();
}
}
}

0 comments on commit 5c447f8

Please sign in to comment.