public async Task Save(UriString host) { logger.Trace("Save: {0}", host); KeychainAdapter credentialAdapter; if (!keychainAdapters.TryGetValue(host, out credentialAdapter)) { throw new ArgumentException($"Host: {host} is not found"); } if (credentialAdapter.OctokitCredentials == Credentials.Anonymous) { throw new InvalidOperationException("Anonymous credentials cannot be stored"); } // create new connection in the connection cache for this host if (connectionCache.ContainsKey(host)) { connectionCache.Remove(host); } connectionCache.Add(host, new Connection { Host = host, Username = credentialAdapter.OctokitCredentials.Login }); // flushes credential cache to disk (host and username only) WriteCacheToDisk(); // saves credential in git credential manager (host, username, token) await credentialManager.Delete(host); await credentialManager.Save(credentialAdapter.Credential); }
private KeychainAdapter AddCredential(UriString host) { var keychainAdapter = GetKeychainAdapter(host); if (string.IsNullOrEmpty(keychainAdapter.Credential.Token)) { throw new InvalidOperationException("Anonymous credentials cannot be stored"); } // saves credential in git credential manager (host, username, token) credentialManager.Delete(host); credentialManager.Save(keychainAdapter.Credential); return(keychainAdapter); }
private async Task <KeychainAdapter> AddCredential(UriString host) { var keychainAdapter = GetKeychainAdapter(host); if (keychainAdapter.OctokitCredentials == Credentials.Anonymous) { throw new InvalidOperationException("Anonymous credentials cannot be stored"); } // saves credential in git credential manager (host, username, token) await credentialManager.Delete(host); await credentialManager.Save(keychainAdapter.Credential); return(keychainAdapter); }