Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }