private void OnSaved() { // Instead of attempting to track/detect what tokens have changed, simply remove all and re-add the current ones. foreach (IVsCredential credential in this.CredentialService.RetrieveAll(UserSettings.CredentialFeatureName)) { this.credentialService.Remove(credential); } foreach (DesignTimeAuthentication authentication in this.MruDesignTimeAuthentications.Where(a => a.RefreshToken != null)) { IVsCredentialKey key = this.GetCredentialKey(authentication); this.CredentialService.Add(key, authentication.RefreshToken); } }
private static void OnLoaded(UserSettings userSettings) { for (int i = userSettings.MruDesignTimeAuthentications.Count() - 1; i >= 0; i--) { DesignTimeAuthentication authentication = userSettings.MruDesignTimeAuthentications[i]; if (authentication.Version != DesignTimeAuthentication.CurrentVersion) { // Currently if the authentication info cached in the MRU does not match the current version // then it is simply removed. At anytime this logic could be modified to perform an upgrade // if the necessary requirements exist. userSettings.MruDesignTimeAuthentications.Remove(authentication); continue; } IVsCredentialKey key = userSettings.GetCredentialKey(authentication); IVsCredential credential = userSettings.CredentialService.Retrieve(key); authentication.RefreshToken = credential == null ? null : credential.TokenValue; } }