/// <summary> /// Generates a new random global GUID and if storeNew is true, it replaces the existing GUID in persistent storage. /// </summary> /// <param name="storeNew">Whether or not to replace the existing GUID in persistent storage</param> /// <returns></returns> public static Guid NewGlobalGuid(bool storeNew = true) { try { //generate a new GUID var newGuid = Guid.NewGuid(); //should we replace the existing GUID? if (storeNew) { //store the new GUID encrypted via WDPAPI var handler = new ProtectedFile(GuidFileLocation); handler.WriteAllText(newGuid.ToString()); } //return the newly generated GUID return(newGuid); } catch { //ignore all errors } //default (all zeroes) return(Guid.Empty); }
public void SaveRecentToken(TokenCacheInfo cacheInfo, string resource) { var file = ProtectedFile.GetCacheFile(resource == Constants.CSMResource ? _recentARMFileName : _recentAADFileName); var json = JObject.FromObject(cacheInfo); ProtectedFile.WriteAllText(ProtectedFile.GetCacheFile(file), json.ToString()); }
public static bool CommitDefaultSettings(this ApplicationOptions settings, bool waitWindow = true) { try { if (waitWindow) { return((bool)WaitWindow.WaitWindow.Show(CommitDefaultSettings, @"Saving settings", settings)); } else { //write all new settings var protectedFile = new ProtectedFile(SettingsFile); protectedFile.WriteAllText(settings.ProfileToXml(), ProtectedSettings); return(true); } } catch (Exception ex) { LoggingHelpers.RecordException(ex.Message, @"CommitToDefaultError"); } //default return(false); }
public void SaveRecentToken(TokenCacheInfo cacheInfo, string resource) { var file = ProtectedFile.GetCacheFile(GetRecentTokenFileName(resource)); var json = JObject.FromObject(cacheInfo); ProtectedFile.WriteAllText(ProtectedFile.GetCacheFile(file), json.ToString()); }
public static bool SaveToken(string token, bool deleteIfPresent = true) { if (deleteIfPresent) { ClearStored(); } try { var protectedToken = new ProtectedFile(Final); if (TokenCachingEnabled) { protectedToken.WriteAllText(token); } return(true); } catch (Exception) { //ignore any errors } //default return(false); }
public void SaveCache(Dictionary <string, TenantCacheInfo> tenants) { var json = JObject.FromObject(tenants); ProtectedFile.WriteAllText(ProtectedFile.GetCacheFile(_fileName), json.ToString()); }
public void SaveCache(CustomTokenCache cache) { var state = cache.GetState(); ProtectedFile.WriteAllText(ProtectedFile.GetCacheFile(_cacheFileName), state); }