private static IObservable <TokenCacheNotificationArgs> ReadStorage(this ITokenCache tokenCache, Func <IObjectSpace> objectspaceFactory, Guid userId) => tokenCache.BeforeAccess().Select(args => { using (var objectSpace = objectspaceFactory()){ var authentication = objectSpace.GetObjectByKey <MSAuthentication>(userId); args.TokenCache.DeserializeMsalV3(authentication?.Token); objectSpace.CommitChanges(); } return(args); });
private static IObservable <TokenCacheNotificationArgs> ReadStorage(this ITokenCache tokenCache, string cacheFilePath) => tokenCache.BeforeAccess() .Select(args => { var bytes = File.Exists(cacheFilePath) ? ProtectedData.Unprotect(File.ReadAllBytes(cacheFilePath), null, DataProtectionScope.CurrentUser) : null; args.TokenCache.DeserializeMsalV3(bytes); return(args); });