// Initializes the cache against a local file. // If the file is already present, it loads its content in the ADAL cache public SettingsFileTokenCache(ISettingsFile settingsFile) { _settingsFile = settingsFile; AfterAccess = AfterAccessNotification; BeforeAccess = BeforeAccessNotification; Deserialize(_settingsFile.ReadAllBytes()); }
public byte[] ReadAllBytes() { var bytes = _file.ReadAllBytes(); if (bytes != null) { return(ProtectedData.Unprotect(bytes, null, DataProtectionScope.CurrentUser)); } else { return(null); } }
// Triggered right before ADAL needs to access the cache. // Reload the cache from the persistent store in case it changed since the last access. private void BeforeAccessNotification(TokenCacheNotificationArgs args) { Deserialize(_settingsFile.ReadAllBytes()); }