Skip to content

Commit

Permalink
NR Serialize MSAL cache on Windows; on Mobile platforms this is done …
Browse files Browse the repository at this point in the history
  • Loading branch information
jbe2277 committed Dec 30, 2023
1 parent 5e7c0f4 commit 073a307
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

<PackageReference Include="Microsoft.Graph" Version="5.37.0" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.58.1" />
<PackageReference Include="Microsoft.Identity.Client.Extensions.Msal" Version="4.58.1" />
<PackageReference Include="System.ServiceModel.Syndication" Version="8.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Graph;
using Microsoft.Identity.Client;
using Microsoft.Identity.Client.Extensions.Msal;
using Microsoft.Kiota.Abstractions.Authentication;
using Waf.NewsReader.Applications.Services;

Expand Down Expand Up @@ -46,8 +47,21 @@ public UserAccount? CurrentAccount
private set => SetProperty(ref currentAccount, value);
}

#if WINDOWS
private bool cacheInitialized;
#endif
public async Task<bool> TrySilentSignIn()
{
#if WINDOWS
if (!cacheInitialized && publicClient is not null)
{
cacheInitialized = true;
var storageProperties = new StorageCreationPropertiesBuilder("msal.dat", Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)).Build();
var cacheHelper = await MsalCacheHelper.CreateAsync(storageProperties);
cacheHelper.RegisterCache(publicClient.UserTokenCache);
}
#endif

try
{
var accessToken = await TrySilentSignInCore();
Expand Down

0 comments on commit 073a307

Please sign in to comment.