private static IObservable <TokenCacheNotificationArgs> WriteStorage(this ITokenCache tokenCache, Func <IObjectSpace> objectspaceFactory, Guid userId) => tokenCache.AfterAccess().Select(args => { using (var objectSpace = objectspaceFactory()){ var authentication = objectSpace.GetObjectByKey <MSAuthentication>(userId) ?? objectSpace.CreateObject <MSAuthentication>(); authentication.Oid = userId; authentication.Token = args.TokenCache.SerializeMsalV3(); objectSpace.CommitChanges(); } return(args); });
private static IObservable <TokenCacheNotificationArgs> WriteStorage(this ITokenCache tokenCache, string cacheFilePath) => tokenCache.AfterAccess() .Select(args => { var bytes = ProtectedData.Protect(args.TokenCache.SerializeMsalV3(), null, DataProtectionScope.CurrentUser); File.WriteAllBytes(cacheFilePath, bytes); return(args); });
private static IObservable <TokenCacheNotificationArgs> WriteStorage(this ITokenCache tokenCache, Func <IObjectSpace> objectSpaceFactory, Guid userId) => tokenCache.AfterAccess().Select(args => {