private async void ToggleSwitch_UseHttpAuth_Toggled(object sender, RoutedEventArgs e)
        {
            if (ToggleSwitch_UseHttpAuth.IsOn)
            {
                var options = new CredentialPickerOptions()
                {
                    TargetName             = resourceLoader.GetString("Prompt_HttpAuth_Title"),
                    Caption                = resourceLoader.GetString("Prompt_HttpAuth_Title"),
                    Message                = resourceLoader.GetString("Prompt_HttpAuth_Message"),
                    CredentialSaveOption   = CredentialSaveOption.Hidden,
                    AuthenticationProtocol = AuthenticationProtocol.Basic
                };

                var result = await CredentialPicker.PickAsync(options);

                if (string.IsNullOrEmpty(result.CredentialUserName) || string.IsNullOrWhiteSpace(result.CredentialUserName))
                {
                    ToggleSwitch_UseHttpAuth.IsOn = false;
                    return;
                }
                else
                {
                    UseHttpAuth             = true;
                    HttpBasicAuthCredential = new HttpBasicAuthCredential(result.CredentialUserName, result.CredentialPassword);
                }
            }
            else
            {
                UseHttpAuth             = false;
                HttpBasicAuthCredential = new HttpBasicAuthCredential();
            }
        }
        private async Task <CredentialPickerResults> AskCredential(bool retry)
        {
            var options = new CredentialPickerOptions()
            {
                AuthenticationProtocol = AuthenticationProtocol.Basic,
                CredentialSaveOption   = CredentialSaveOption.Selected,
                CallerSavesCredential  = true,
                Caption    = retry ? resourceLoader.GetString("CredentialPickerRetryCaption") : resourceLoader.GetString("CredentialPickerCaption"),
                Message    = retry ? resourceLoader.GetString("CredentialPickerRetryMessage") : resourceLoader.GetString("CredentialPickerMessage"),
                TargetName = "."
            };

            return(await CredentialPicker.PickAsync(options));
        }
예제 #3
0
        private async Task <CredentialResult> PromptForCredentials(String resource)
        {
            CredentialResult credential = null;

            CredentialPickerOptions options = new CredentialPickerOptions
            {
                Message = "Your credentials will be used to connect to JabbR.",
                Caption = "Please enter your JabbR username and password.",
                CredentialSaveOption   = CredentialSaveOption.Unselected,
                AuthenticationProtocol = 0,
                TargetName             = resource,
            };

            var result = await CredentialPicker.PickAsync(options);

            if (result.ErrorCode == 0)
            {
                credential = new CredentialResult(result.CredentialUserName, result.CredentialPassword);
            }

            return(credential);
        }
예제 #4
0
        private async void Launch_Click(object sender, RoutedEventArgs e)
        {
            if ((Target.Text == "") || (Message.Text == "") || (Caption.Text == ""))
            {
                return;
            }

            CredentialPickerOptions credPickerOptions = new CredentialPickerOptions();

            credPickerOptions.Message             = Message.Text;
            credPickerOptions.Caption             = Caption.Text;
            credPickerOptions.TargetName          = Target.Text;
            credPickerOptions.AlwaysDisplayDialog = (AlwaysShowDialog.IsChecked == true);
            if (ProtocolSelection.SelectedItem == null)
            {
                //default protocol, if no selection
                credPickerOptions.AuthenticationProtocol = AuthenticationProtocol.Negotiate;
            }
            else
            {
                string selectedProtocol = ((ComboBoxItem)ProtocolSelection.SelectedItem).Content.ToString();
                if (selectedProtocol.Equals("Kerberos", StringComparison.CurrentCultureIgnoreCase))
                {
                    credPickerOptions.AuthenticationProtocol = AuthenticationProtocol.Kerberos;
                }
                else if (selectedProtocol.Equals("Negotiate", StringComparison.CurrentCultureIgnoreCase))
                {
                    credPickerOptions.AuthenticationProtocol = AuthenticationProtocol.Negotiate;
                }
                else if (selectedProtocol.Equals("NTLM", StringComparison.CurrentCultureIgnoreCase))
                {
                    credPickerOptions.AuthenticationProtocol = AuthenticationProtocol.Ntlm;
                }
                else if (selectedProtocol.Equals("CredSsp", StringComparison.CurrentCultureIgnoreCase))
                {
                    credPickerOptions.AuthenticationProtocol = AuthenticationProtocol.CredSsp;
                }
                else if (selectedProtocol.Equals("Basic", StringComparison.CurrentCultureIgnoreCase))
                {
                    credPickerOptions.AuthenticationProtocol = AuthenticationProtocol.Basic;
                }
                else if (selectedProtocol.Equals("Digest", StringComparison.CurrentCultureIgnoreCase))
                {
                    credPickerOptions.AuthenticationProtocol = AuthenticationProtocol.Digest;
                }
                else if (selectedProtocol.Equals("Custom", StringComparison.CurrentCultureIgnoreCase))
                {
                    if (CustomProtocol.Text != null && CustomProtocol.Text != String.Empty)
                    {
                        credPickerOptions.AuthenticationProtocol       = AuthenticationProtocol.Custom;
                        credPickerOptions.CustomAuthenticationProtocol = CustomProtocol.Text;
                    }
                    else
                    {
                        rootPage.NotifyUser("Please enter a custom protocol", NotifyType.ErrorMessage);
                    }
                }
            }

            if (SaveCheckboxSelection.SelectedItem != null)
            {
                string checkboxState = ((ComboBoxItem)SaveCheckboxSelection.SelectedItem).Content.ToString();
                if (checkboxState.Equals("Hidden", StringComparison.CurrentCultureIgnoreCase))
                {
                    credPickerOptions.CredentialSaveOption = CredentialSaveOption.Hidden;
                }
                else if (checkboxState.Equals("Selected", StringComparison.CurrentCultureIgnoreCase))
                {
                    credPickerOptions.CredentialSaveOption = CredentialSaveOption.Selected;
                }
                else if (checkboxState.Equals("Unselected", StringComparison.CurrentCultureIgnoreCase))
                {
                    credPickerOptions.CredentialSaveOption = CredentialSaveOption.Unselected;
                }
            }

            var credPickerResults = await Windows.Security.Credentials.UI.CredentialPicker.PickAsync(credPickerOptions);

            SetResult(credPickerResults);
        }
예제 #5
0
        private IAsyncOperation<CredentialPickerResults> SelectCredentialAsync( CredentialInteraction interaction )
        {
            Contract.Requires( interaction != null );
            Contract.Ensures( Contract.Result<IAsyncOperation<CredentialPickerResults>>() != null );

            var content = interaction == null ? string.Empty : interaction.Content.ToString();
            var options = new CredentialPickerOptions()
            {
                AlwaysDisplayDialog = AlwaysDisplayDialog,
                AuthenticationProtocol = AuthenticationProtocol,
                CallerSavesCredential = CallerSavesCredential,
                CredentialSaveOption = CredentialSaveOption,
                Caption = interaction.Title,
                Message = content,
                PreviousCredential = interaction.Credential.AsBuffer(),
            };

            if ( !string.IsNullOrEmpty( CustomAuthenticationProtocol ) )
                options.CustomAuthenticationProtocol = CustomAuthenticationProtocol;

            if ( !string.IsNullOrEmpty( TargetName ) )
                options.TargetName = TargetName;

            return CredentialPicker.PickAsync( options );
        }