public static void DeleteCredentials(Program program, OperationArguments operationArguments) { if (ReferenceEquals(operationArguments, 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}'."); BaseVstsAuthentication vstsAuth = authentication as BaseVstsAuthentication; vstsAuth.DeleteCredentials(operationArguments.TargetUri); break; case AuthorityType.GitHub: Git.Trace.WriteLine($"deleting GitHub credentials for '{operationArguments.TargetUri}'."); Github.Authentication 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() { 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."); }