示例#1
0
        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;
            }
        }
示例#2
0
        private static BaseAuthentication CreateAuthentication(OperationArguments operationArguments)
        {
            Debug.Assert(operationArguments != null, "The operationArguments is null");

            Trace.WriteLine("Program::CreateAuthentication");

            var secrets = new SecretStore(SecretsNamespace);
            BaseAuthentication authority = null;

            switch (operationArguments.Authority)
            {
            case AuthorityType.Auto:
                Trace.WriteLine("   detecting authority type");

                // detect the authority
                if (BaseVsoAuthentication.GetAuthentication(operationArguments.TargetUri,
                                                            VsoCredentialScope,
                                                            secrets,
                                                            null,
                                                            out authority) ||
                    GithubAuthentication.GetAuthentication(operationArguments.TargetUri,
                                                           GithubCredentialScope,
                                                           secrets,
                                                           out authority))
                {
                    // set the authority type based on the returned value
                    if (authority is VsoMsaAuthentication)
                    {
                        operationArguments.Authority = AuthorityType.MicrosoftAccount;
                        goto case AuthorityType.MicrosoftAccount;
                    }
                    else if (authority is VsoAadAuthentication)
                    {
                        operationArguments.Authority = AuthorityType.AzureDirectory;
                        goto case AuthorityType.AzureDirectory;
                    }
                    else if (authority is GithubAuthentication)
                    {
                        operationArguments.Authority = AuthorityType.GitHub;
                        goto case AuthorityType.GitHub;
                    }
                }

                operationArguments.Authority = AuthorityType.Basic;
                goto case AuthorityType.Basic;

            case AuthorityType.AzureDirectory:
                Trace.WriteLine("   authority is Azure Directory");

                Guid tenantId = Guid.Empty;
                // return the allocated authority or a generic AAD backed VSO authentication object
                return(authority ?? new VsoAadAuthentication(Guid.Empty, VsoCredentialScope, secrets));

            case AuthorityType.Basic:
            default:
                Trace.WriteLine("   authority is basic");

                // return a generic username + password authentication object
                return(authority ?? new BasicAuthentication(secrets));

            case AuthorityType.GitHub:
                Trace.WriteLine("    authority it GitHub");

                // return a GitHub authenitcation object
                return(authority ?? new GithubAuthentication(GithubCredentialScope, secrets));

            case AuthorityType.MicrosoftAccount:
                Trace.WriteLine("   authority is Microsoft Live");

                // return the allocated authority or a generic MSA backed VSO authentication object
                return(authority ?? new VsoMsaAuthentication(VsoCredentialScope, secrets));
            }
        }