예제 #1
0
        public static bool AuthenticationCodeModalPrompt(TargetUri targetUri, GithubAuthenticationResultType resultType, string username, out string authenticationCode)
        {
            Trace.WriteLine("Program::GithubAuthcodeModalPrompt");

            var twoFactorViewModel = new TwoFactorViewModel(resultType == GithubAuthenticationResultType.TwoFactorSms);

            Trace.WriteLine("   prompting user for authentication code.");

            bool authenticationCodeValid = ShowViewModel(twoFactorViewModel, () => new TwoFactorWindow());

            authenticationCode = authenticationCodeValid
                ? twoFactorViewModel.AuthenticationCode
                : null;

            return(authenticationCodeValid);
        }
        public static bool AuthenticationCodeModalPrompt(TargetUri targetUri, GithubAuthenticationResultType resultType, string username, out string authenticationCode)
        {
            Trace.WriteLine("Program::GithubAuthcodeModalPrompt");

            var twoFactorViewModel = new TwoFactorViewModel(resultType == GithubAuthenticationResultType.TwoFactorSms);

            Trace.WriteLine("   prompting user for authentication code.");

            bool authenticationCodeValid = ShowViewModel(twoFactorViewModel, () => new TwoFactorWindow());

            authenticationCode = authenticationCodeValid
                ? twoFactorViewModel.AuthenticationCode
                : null;

            return authenticationCodeValid;
        }
        private static bool GithubAuthCodePrompt(Uri targetUri, GithubAuthenticationResultType resultType, out string authenticationCode)
        {
            // ReadConsole 32768 fail, 32767 ok
            // @linquize [https://github.com/Microsoft/Git-Credential-Manager-for-Windows/commit/a62b9a19f430d038dcd85a610d97e5f763980f85]
            const int BufferReadSize = 32 * 1024 - 7;

            StringBuilder buffer = new StringBuilder(BufferReadSize);
            uint read = 0;
            uint written = 0;

            authenticationCode = null;

            NativeMethods.FileAccess fileAccessFlags = NativeMethods.FileAccess.GenericRead | NativeMethods.FileAccess.GenericWrite;
            NativeMethods.FileAttributes fileAttributes = NativeMethods.FileAttributes.Normal;
            NativeMethods.FileCreationDisposition fileCreationDisposition = NativeMethods.FileCreationDisposition.OpenExisting;
            NativeMethods.FileShare fileShareFlags = NativeMethods.FileShare.Read | NativeMethods.FileShare.Write;

            using (SafeFileHandle stdout = NativeMethods.CreateFile(NativeMethods.ConsoleOutName, fileAccessFlags, fileShareFlags, IntPtr.Zero, fileCreationDisposition, fileAttributes, IntPtr.Zero))
            using (SafeFileHandle stdin = NativeMethods.CreateFile(NativeMethods.ConsoleInName, fileAccessFlags, fileShareFlags, IntPtr.Zero, fileCreationDisposition, fileAttributes, IntPtr.Zero))
            {
                string type = resultType == GithubAuthenticationResultType.TwoFactorApp
                    ? "app"
                    : "sms";
                buffer.AppendLine()
                      .Append("authcode (")
                      .Append(type)
                      .Append("): ");
                if (!NativeMethods.WriteConsole(stdout, buffer, (uint)buffer.Length, out written, IntPtr.Zero))
                {
                    int error = Marshal.GetLastWin32Error();
                    throw new Win32Exception(error, "Unable to write to standard output (" + error + ").");
                }
                buffer.Clear();

                // read input from the user
                if (!NativeMethods.ReadConsole(stdin, buffer, BufferReadSize, out read, IntPtr.Zero))
                {
                    int error = Marshal.GetLastWin32Error();
                    throw new Win32Exception(error, "Unable to read from standard input (" + error + ").");
                }

                authenticationCode = buffer.ToString(0, (int)read);
                authenticationCode = authenticationCode.Trim(Environment.NewLine.ToCharArray());
            }

            return authenticationCode != null;
        }
        private static bool GithubAuthcodeModalPrompt(Uri targetUri, GithubAuthenticationResultType resultType, string username, out string authenticationCode)
        {
            Trace.WriteLine("Program::GithubAuthcodeModalPrompt");

            authenticationCode = null;

            string type =
                resultType == GithubAuthenticationResultType.TwoFactorApp
                    ? "app"
                    : "sms";
            string message = String.Format("Enter {0} authentication code for {1}://{2}.", type, targetUri.Scheme, targetUri.DnsSafeHost);

            Trace.WriteLine("   prompting user for authentication code.");

            return ModalPromptForPassword(targetUri, message, username, out authenticationCode);
        }
예제 #5
0
 public GithubAuthenticationResult(GithubAuthenticationResultType type)
 {
     Type  = type;
     Token = null;
 }
예제 #6
0
 public GithubAuthenticationResult(GithubAuthenticationResultType type, Token token)
 {
     Type  = type;
     Token = token;
 }
        private static bool GithubAuthCodeModalPrompt( Uri targetUri, GithubAuthenticationResultType resultType, string username, out string authenticationCode ) {
            string temp;
            string password;

            var result = PromptForCredentialsBase( targetUri, out temp, out password,
                string.Format( "Enter {0} authentication code for {1}://{2}.",
                    resultType == GithubAuthenticationResultType.TwoFactorApp ? "app" : "sms",
                    targetUri.Scheme, targetUri.DnsSafeHost ), username );

            authenticationCode = "";

            if ( !string.IsNullOrWhiteSpace( password ) ) {
                authenticationCode = password;
            } else {
                authenticationCode = null;
            }

            return authenticationCode != null;
        }
 public GithubAuthenticationResult(GithubAuthenticationResultType type)
 {
     Type = type;
     Token = null;
 }
 public GithubAuthenticationResult(GithubAuthenticationResultType type, Token token)
 {
     Type = type;
     Token = token;
 }