private async void ShowLogin() { CredentialPickerOptions opt = new CredentialPickerOptions(); opt.AuthenticationProtocol = AuthenticationProtocol.Basic; opt.Message = CultureHelper.GetLocalString("Login to BettrDiet with your email adress|Mit deiner email Adresse bei BettrDiet anmelden"); opt.TargetName = "."; opt.Caption = "BettrDiet Login"; opt.CredentialSaveOption = CredentialSaveOption.Selected; var vault = new Windows.Security.Credentials.PasswordVault(); var vm = DataContext as BettrDiet.Core.ViewModels.LoginViewModel; var credentialPicker = await Windows.Security.Credentials.UI.CredentialPicker.PickAsync(opt); if (credentialPicker.ErrorCode!=0) { vm.DoClose(); } if (credentialPicker.CredentialUserName != null && credentialPicker.CredentialPassword != null) { if (credentialPicker.CredentialSaveOption == CredentialSaveOption.Selected) { var s = credentialPicker.Credential; var str = System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBufferExtensions.AsStream(s); byte[] bytes = new byte[100]; var sr = new System.IO.StreamReader(str); while (!sr.EndOfStream) { var line = await sr.ReadLineAsync(); Debug.WriteLine("line:" + line); } vm.Username = credentialPicker.CredentialUserName; vm.Pwd = credentialPicker.CredentialPassword; var ret=await vm.DoLogin(); if (!string.IsNullOrEmpty(ret)) { ShowLogin(); } } } }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> protected override async void OnNavigatedTo(NavigationEventArgs e) { string userName, password; bool saveCredentials = false; PasswordCredential credential = null; AnimationLibrary.AnimateOpacity(this.background, 1.0, 2.0); AnimationLibrary.AnimateX(this.logo, -275, 0.5); try { var passwordVault = new PasswordVault(); credential = passwordVault.FindAllByResource("Music8")[0]; credential = passwordVault.Retrieve("Music8", credential.UserName); } catch (Exception exception) { } if (credential == null) { CredentialPickerOptions credPickerOptions = new CredentialPickerOptions(); credPickerOptions.Message = "Enter your Google Music credentials"; credPickerOptions.Caption = "Login to Music8"; credPickerOptions.TargetName = "."; credPickerOptions.AlwaysDisplayDialog = true; credPickerOptions.AuthenticationProtocol = AuthenticationProtocol.Basic; var credPickerResults = await CredentialPicker.PickAsync(credPickerOptions); userName = credPickerResults.CredentialUserName; password = credPickerResults.CredentialPassword; saveCredentials = credPickerResults.CredentialSaveOption == CredentialSaveOption.Selected; } else { userName = credential.UserName; password = credential.Password; } DoLogin(userName, password, saveCredentials); }
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 (Protocol.SelectedItem == null) { //default protocol, if no selection credPickerOptions.AuthenticationProtocol = AuthenticationProtocol.Negotiate; } else { string selectedProtocol = ((ComboBoxItem)Protocol.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 (CheckboxState.SelectedItem != null) { string checkboxState = ((ComboBoxItem)CheckboxState.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); }
public async Task<bool> Logon(CancellationToken ct) { string jsonresultUserAuth = ""; string sAppUser = ""; CredentialPickerOptions co = new CredentialPickerOptions(); co.Message = "Please enter your logid and password."; co.AuthenticationProtocol = AuthenticationProtocol.Basic; co.AlwaysDisplayDialog = true; co.Caption = "Allscripts Wand"; co.TargetName = this.ToString(); co.CallerSavesCredential = false; co.CredentialSaveOption = CredentialSaveOption.Hidden; CredentialPickerResults credPickerResults = await CredentialPicker.PickAsync(co).AsTask(ct); if (credPickerResults.ErrorCode == 0) { if (string.IsNullOrEmpty(objUnityData.UnityURL)) { MessageDialog md = new MessageDialog("Unity URL not set. please set this in the Settings charm and try again."); await md.ShowAsync(); // m_sURL = "http://10.160.146.32/unity/unityservice.svc/json/"; // UnityData.UnityURL = m_sURL; return false; } UnityDataAccess uda = new UnityDataAccess(); //todo remove dztest harcodes, make appname for metro string sToken = await uda.GetToken(objUnityData.UnitySvcUser, objUnityData.UnitySvcPwd, objUnityData.UnityAppUser); //set once for the app. if (!string.IsNullOrEmpty(sToken)) objUnityData.Token = sToken; //todo make this xml string accurate with device names. string sXML = "<context><identifier>3baf035536659932886622bc99820eb5d6980bee</identifier><model>test</model>" + "<deviceName>testdev</deviceName><systemName>metro</systemName><systemVersion>4.3.5</systemVersion>" + "<appVersion>1.0</appVersion></context>"; //use jmedici demo if no creds are supplied. if (string.IsNullOrEmpty(credPickerResults.CredentialUserName)) { string spwd = "password01"; jsonresultUserAuth = await uda.Magic("getuserauthentication", "jmedici", objUnityData.UnityAppName, "", sToken, spwd, "", "1.0", sXML, "", string.Empty, null); sAppUser = "******"; } else { jsonresultUserAuth = await uda.Magic("getuserauthentication", credPickerResults.CredentialUserName.ToString(), objUnityData.UnityAppName, "", sToken, credPickerResults.CredentialPassword.ToString(), "", "1.0", sXML, "", string.Empty, null); sAppUser = credPickerResults.CredentialUserName.ToString(); } // JArray obj = Newtonsoft.Json.Linq.JArray.Parse(jsonresultUserAuth); JObject jo = JObject.Parse(obj[0].ToString()); //todo handle invalid and locked out users. string sValidUser = ((string)jo["getuserauthenticationinfo"][0]["ValidUser"]); string sLockOut = ((string)jo["getuserauthenticationinfo"][0]["Lockout"]); string sError = ((string)jo["getuserauthenticationinfo"][0]["ErrorMessage"]); if (!string.IsNullOrEmpty(sError)) { MessageDialog md = new MessageDialog("login error :" + sError); await md.ShowAsync(); // await Logon(ct); return false; } else { objUnityData.UnityAppUser = sAppUser ; return true; } } else { return false; } }