private static 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 OperationArguments operationArguments = new OperationArguments(Console.In); Debug.Assert(operationArguments != null, "The operationArguments is null"); Debug.Assert(operationArguments.TargetUri != null, "The operationArgument.TargetUri is null"); LoadOperationArguments(operationArguments); EnableTraceLogging(operationArguments); Trace.WriteLine("Program::Erase"); Trace.WriteLine(" targetUri = " + operationArguments.TargetUri); BaseAuthentication authentication = CreateAuthentication(operationArguments); switch (operationArguments.Authority) { default: case AuthorityType.Basic: authentication.DeleteCredentials(operationArguments.TargetUri); break; case AuthorityType.AzureDirectory: case AuthorityType.MicrosoftAccount: BaseVsoAuthentication vsoAuth = authentication as BaseVsoAuthentication; vsoAuth.DeleteCredentials(operationArguments.TargetUri); break; } }
public static async Task <bool> DeleteCredentials(Program program, OperationArguments operationArguments) { if (program is null) { throw new ArgumentNullException(nameof(program)); } if (operationArguments is null) { throw new ArgumentNullException(nameof(operationArguments)); } BaseAuthentication authentication = await program.CreateAuthentication(operationArguments); switch (operationArguments.Authority) { default: case AuthorityType.Basic: { program.Trace.WriteLine($"deleting basic credentials for '{operationArguments.TargetUri}'."); return(await authentication.DeleteCredentials(operationArguments.TargetUri)); } case AuthorityType.AzureDirectory: case AuthorityType.MicrosoftAccount: { program.Trace.WriteLine($"deleting VSTS credentials for '{operationArguments.TargetUri}'."); var vstsAuth = authentication as Vsts.Authentication; return(await vstsAuth.DeleteCredentials(operationArguments.TargetUri)); } case AuthorityType.GitHub: { program.Trace.WriteLine($"deleting GitHub credentials for '{operationArguments.TargetUri}'."); var ghAuth = authentication as Github.Authentication; return(await ghAuth.DeleteCredentials(operationArguments.TargetUri)); } case AuthorityType.Bitbucket: { program.Trace.WriteLine($"deleting Bitbucket credentials for '{operationArguments.TargetUri}'."); var bbAuth = authentication as Bitbucket.Authentication; return(await bbAuth.DeleteCredentials(operationArguments.TargetUri, operationArguments.Username)); } } }
public static void DeleteCredentials(Program program, OperationArguments operationArguments) { if (operationArguments is null) { throw new ArgumentNullException("operationArguments"); } var task = Task.Run(async() => { return(await program.CreateAuthentication(operationArguments)); }); BaseAuthentication authentication = task.Result; switch (operationArguments.Authority) { default: case AuthorityType.Basic: Git.Trace.WriteLine($"deleting basic credentials for '{operationArguments.TargetUri}'."); authentication.DeleteCredentials(operationArguments.TargetUri); break; case AuthorityType.AzureDirectory: case AuthorityType.MicrosoftAccount: Git.Trace.WriteLine($"deleting VSTS credentials for '{operationArguments.TargetUri}'."); var vstsAuth = authentication as BaseVstsAuthentication; vstsAuth.DeleteCredentials(operationArguments.TargetUri); break; case AuthorityType.GitHub: Git.Trace.WriteLine($"deleting GitHub credentials for '{operationArguments.TargetUri}'."); var ghAuth = authentication as Github.Authentication; ghAuth.DeleteCredentials(operationArguments.TargetUri); break; case AuthorityType.Bitbucket: Git.Trace.WriteLine($"deleting Bitbucket credentials for '{operationArguments.TargetUri}'."); var bbAuth = authentication as Bitbucket.Authentication; bbAuth.DeleteCredentials(operationArguments.TargetUri, operationArguments.CredUsername); break; } }
private static void Delete() { string[] args = Environment.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 = Console.OpenStandardInput()) { OperationArguments operationArguments = new OperationArguments(stdin); operationArguments.QueryUri = uri; LoadOperationArguments(operationArguments); BaseAuthentication authentication = CreateAuthentication(operationArguments); switch (operationArguments.Authority) { default: case AuthorityType.Basic: Git.Trace.WriteLine($"deleting basic credentials for '{operationArguments.TargetUri}'."); break; case AuthorityType.AzureDirectory: case AuthorityType.MicrosoftAccount: Git.Trace.WriteLine($"deleting VSTS credentials for '{operationArguments.TargetUri}'."); break; case AuthorityType.GitHub: Git.Trace.WriteLine($"deleting GitHub credentials for '{operationArguments.TargetUri}'."); break; case AuthorityType.Ntlm: Git.Trace.WriteLine($"deleting NTLM credentials for '{operationArguments.TargetUri}'."); break; } authentication.DeleteCredentials(operationArguments.TargetUri); } return; error_parse: Die("Unable to parse target URI."); }
private static void Delete() { Trace.WriteLine("Program::Erase"); string[] args = Environment.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; } } var stdin = Console.OpenStandardInput(); OperationArguments operationArguments = new OperationArguments(stdin); operationArguments.QueryUri = uri; LoadOperationArguments(operationArguments); BaseAuthentication authentication = CreateAuthentication(operationArguments); switch (operationArguments.Authority) { default: case AuthorityType.Basic: Trace.WriteLine(" deleting basic credentials"); authentication.DeleteCredentials(operationArguments.TargetUri); break; case AuthorityType.AzureDirectory: case AuthorityType.MicrosoftAccount: Trace.WriteLine(" deleting VSTS credentials"); BaseVstsAuthentication vstsAuth = authentication as BaseVstsAuthentication; vstsAuth.DeleteCredentials(operationArguments.TargetUri); // call delete twice to purge any stored ADA tokens vstsAuth.DeleteCredentials(operationArguments.TargetUri); break; case AuthorityType.GitHub: Trace.WriteLine(" deleting GitHub credentials"); GitHubAuthentication ghAuth = authentication as GitHubAuthentication; ghAuth.DeleteCredentials(operationArguments.TargetUri); break; } return; error_parse: Console.Error.WriteLine("Fatal: unable to parse target URI."); }
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."); }
internal void Delete() { string[] args = Environment.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) { OperationArguments operationArguments = new OperationArguments(stdin) { QueryUri = uri }; LoadOperationArguments(operationArguments); var task = Task.Run(async() => { return(await CreateAuthentication(operationArguments)); }); BaseAuthentication authentication = task.Result; switch (operationArguments.Authority) { default: case AuthorityType.Basic: Git.Trace.WriteLine($"deleting basic credentials for '{operationArguments.TargetUri}'."); break; case AuthorityType.AzureDirectory: case AuthorityType.MicrosoftAccount: Git.Trace.WriteLine($"deleting VSTS credentials for '{operationArguments.TargetUri}'."); break; case AuthorityType.GitHub: Git.Trace.WriteLine($"deleting GitHub credentials for '{operationArguments.TargetUri}'."); break; case AuthorityType.Ntlm: Git.Trace.WriteLine($"deleting NTLM credentials for '{operationArguments.TargetUri}'."); break; case AuthorityType.Bitbucket: Git.Trace.WriteLine($"deleting Bitbucket credentials for '{operationArguments.Username}@{operationArguments.TargetUri}'."); break; } authentication.DeleteCredentials(operationArguments.TargetUri, operationArguments.Username); } return; error_parse: Die("Unable to parse target URI."); }