internal void Erase() { // parse the operations arguments from stdin (this is how git sends commands) // see: https://www.kernel.org/pub/software/scm/git/docs/technical/api-credentials.html // see: https://www.kernel.org/pub/software/scm/git/docs/git-credential.html using (var stdin = InStream) { var operationArguments = new OperationArguments(_context); Task.Run(async() => { await operationArguments.ReadInput(stdin); if (operationArguments.TargetUri is null) { var inner = new ArgumentNullException(nameof(operationArguments.TargetUri)); throw new ArgumentException(inner.Message, nameof(operationArguments), inner); } await LoadOperationArguments(operationArguments); EnableTraceLogging(operationArguments); // Set the parent window handle. ParentHwnd = operationArguments.ParentHwnd; if (operationArguments.PreserveCredentials) { _context.Trace.WriteLine($"{KeyTypeName(KeyType.PreserveCredentials)} = true, canceling erase request."); return; } await DeleteCredentials(operationArguments); }).Wait(); } }
internal void Get() { // Parse the operations arguments from stdin (this is how git sends commands) // see: https://www.kernel.org/pub/software/scm/git/docs/technical/api-credentials.html // see: https://www.kernel.org/pub/software/scm/git/docs/git-credential.html using (var stdin = InStream) { var operationArguments = new OperationArguments(_context); Task.Run(async() => { await operationArguments.ReadInput(stdin); if (operationArguments.TargetUri is null) { var inner = new ArgumentNullException(nameof(operationArguments.TargetUri)); throw new ArgumentException(inner.Message, nameof(operationArguments), inner); } // Load operation arguments. await LoadOperationArguments(operationArguments); EnableTraceLogging(operationArguments); // Read the details of any git-remote-http(s).exe parent process, but only if // an override hasn't been set which would override the git-remote details. if (string.IsNullOrEmpty(operationArguments.UrlOverride)) { ReadGitRemoteDetails(operationArguments); } // Set the parent window handle. ParentHwnd = operationArguments.ParentHwnd; Credential credentials; if ((credentials = await QueryCredentials(operationArguments)) == null) { Exit(-1, LogonFailedMessage); } else { using (var stdout = OutStream) { operationArguments.WriteToStream(stdout); } } }).Wait(); } }
internal void Erase() { // parse the operations arguments from stdin (this is how git sends commands) // see: https://www.kernel.org/pub/software/scm/git/docs/technical/api-credentials.html // see: https://www.kernel.org/pub/software/scm/git/docs/git-credential.html using (var stdin = InStream) { var operationArguments = new OperationArguments(_context); Task.Run(async() => { await operationArguments.ReadInput(stdin); if (operationArguments.TargetUri is null) { var inner = new ArgumentNullException(nameof(operationArguments.TargetUri)); throw new ArgumentException(inner.Message, nameof(operationArguments), inner); } // Load operation arguments. await LoadOperationArguments(operationArguments); EnableTraceLogging(operationArguments); // Read the details of any git-remote-http(s).exe parent process, but only if // an override hasn't been set which would override the git-remote details. if (string.IsNullOrEmpty(operationArguments.UrlOverride)) { ReadGitRemoteDetails(operationArguments); } // Set the parent window handle. ParentHwnd = operationArguments.ParentHwnd; if (operationArguments.PreserveCredentials) { _context.Trace.WriteLine($"{KeyTypeName(KeyType.PreserveCredentials)} = true, canceling erase request."); return; } await DeleteCredentials(operationArguments); }).Wait(); } }
internal void Get() { // Parse the operations arguments from stdin (this is how git sends commands) // see: https://www.kernel.org/pub/software/scm/git/docs/technical/api-credentials.html // see: https://www.kernel.org/pub/software/scm/git/docs/git-credential.html using (var stdin = InStream) { OperationArguments operationArguments = new OperationArguments(_context); Task.Run(async() => { await operationArguments.ReadInput(stdin); if (operationArguments.TargetUri is null) { var inner = new ArgumentNullException(nameof(operationArguments.TargetUri)); throw new ArgumentException(inner.Message, nameof(operationArguments), inner); } await LoadOperationArguments(operationArguments); EnableTraceLogging(operationArguments); // Set the parent window handle. ParentHwnd = operationArguments.ParentHwnd; Credential credentials; if ((credentials = await QueryCredentials(operationArguments)) == null) { Exit(-1, "Logon failed, use ctrl+c to cancel basic credential prompt."); } else { using (var stdout = OutStream) { operationArguments.WriteToStream(stdout); } } }).Wait(); } }
internal void Store() { // parse the operations arguments from stdin (this is how git sends commands) // see: https://www.kernel.org/pub/software/scm/git/docs/technical/api-credentials.html // see: https://www.kernel.org/pub/software/scm/git/docs/git-credential.html using (var stdin = InStream) { var operationArguments = new OperationArguments(_context); Task.Run(async() => { await operationArguments.ReadInput(stdin); if (operationArguments.TargetUri is null) { var inner = new ArgumentNullException(nameof(operationArguments.TargetUri)); throw new ArgumentException(inner.Message, nameof(operationArguments), inner); } if (operationArguments.Username is null) { var inner = new ArgumentNullException(nameof(operationArguments.Username)); throw new ArgumentException(inner.Message, nameof(operationArguments), inner); } // Load operation arguments. await LoadOperationArguments(operationArguments); EnableTraceLogging(operationArguments); // Read the details of any git-remote-http(s).exe parent process, but only if // an override hasn't been set which would override the git-remote details. if (string.IsNullOrEmpty(operationArguments.UrlOverride)) { ReadGitRemoteDetails(operationArguments); } // Set the parent window handle. ParentHwnd = operationArguments.ParentHwnd; var credentials = operationArguments.Credentials; BaseAuthentication authentication = await CreateAuthentication(operationArguments);; switch (operationArguments.Authority) { default: case AuthorityType.Basic: Trace.WriteLine($"storing basic credentials for '{operationArguments.TargetUri}'."); break; case AuthorityType.Bitbucket: Trace.WriteLine($"storing Bitbucket credentials for '{operationArguments.TargetUri}'."); break; case AuthorityType.AzureDirectory: case AuthorityType.MicrosoftAccount: Trace.WriteLine($"storing VSTS credentials for '{operationArguments.TargetUri}'."); break; case AuthorityType.GitHub: Trace.WriteLine($"storing GitHub credentials for '{operationArguments.TargetUri}'."); break; case AuthorityType.Ntlm: Trace.WriteLine($"storing NTLM credentials for '{operationArguments.TargetUri}'."); break; } await authentication.SetCredentials(operationArguments.TargetUri, credentials); }).Wait(); } }
internal void Delete() { string[] args = Settings.GetCommandLineArgs(); if (args.Length < 3) { goto error_parse; } string url = args[2]; Uri uri = null; if (Uri.IsWellFormedUriString(url, UriKind.Absolute)) { if (!Uri.TryCreate(url, UriKind.Absolute, out uri)) { goto error_parse; } } else { url = string.Format("{0}://{1}", Uri.UriSchemeHttps, url); if (!Uri.TryCreate(url, UriKind.Absolute, out uri)) { goto error_parse; } } using (var stdin = InStream) { var operationArguments = new OperationArguments(_context) { QueryUri = uri }; Task.Run(async() => { await operationArguments.ReadInput(stdin); if (operationArguments.TargetUri is null) { var inner = new ArgumentNullException(nameof(operationArguments.TargetUri)); throw new ArgumentException(inner.Message, nameof(operationArguments), inner); } // Load operation arguments. await LoadOperationArguments(operationArguments); EnableTraceLogging(operationArguments); // Set the parent window handle. ParentHwnd = operationArguments.ParentHwnd; BaseAuthentication authentication = await CreateAuthentication(operationArguments); switch (operationArguments.Authority) { default: case AuthorityType.Basic: _context.Trace.WriteLine($"deleting basic credentials for '{operationArguments.TargetUri}'."); break; case AuthorityType.AzureDirectory: case AuthorityType.MicrosoftAccount: _context.Trace.WriteLine($"deleting VSTS credentials for '{operationArguments.TargetUri}'."); break; case AuthorityType.GitHub: _context.Trace.WriteLine($"deleting GitHub credentials for '{operationArguments.TargetUri}'."); break; case AuthorityType.Ntlm: _context.Trace.WriteLine($"deleting NTLM credentials for '{operationArguments.TargetUri}'."); break; case AuthorityType.Bitbucket: _context.Trace.WriteLine($"deleting Bitbucket credentials for '{operationArguments.Username}@{operationArguments.TargetUri}'."); break; } await authentication.DeleteCredentials(operationArguments.TargetUri, operationArguments.Username); }).Wait(); } return; error_parse: Die("Unable to parse target URI."); }