// Handle the OnLoginEntered event from the login UI // LoginEventArgs contains the username and password that were entered private async void LoginEntered(object sender, LoginEventArgs e) { // Make sure the task completion source has all the information needed if (_loginTaskCompletionSource == null || _loginTaskCompletionSource.Task == null || _loginTaskCompletionSource.Task.AsyncState == null) { return; } try { // Get the associated CredentialRequestInfo (will need the URI of the service being accessed) CredentialRequestInfo requestInfo = _loginTaskCompletionSource.Task.AsyncState as CredentialRequestInfo; // Create a token credential using the provided username and password TokenCredential userCredentials = await AuthenticationManager.Current.GenerateCredentialAsync (requestInfo.ServiceUri, e.Username, e.Password, requestInfo.GenerateTokenOptions); // Set the result on the task completion source _loginTaskCompletionSource.TrySetResult(userCredentials); } catch (Exception ex) { // Unable to create credential, set the exception on the task completion source _loginTaskCompletionSource.TrySetException(ex); } finally { // Get rid of the login controls _loginUI.Hide(); _loginUI = null; } }
// Handle the OnLoginEntered event from the login UI // LoginEventArgs contains the username, password, and domain that were entered private async void LoginInfoEntered(object sender, LoginEventArgs e) { // Make sure the task completion source has all the information needed if (_loginTaskCompletionSrc == null || _loginTaskCompletionSrc.Task == null || _loginTaskCompletionSrc.Task.AsyncState == null) { return; } try { // Get the associated CredentialRequestInfo (will need the URI of the service being accessed) CredentialRequestInfo requestInfo = _loginTaskCompletionSrc.Task.AsyncState as CredentialRequestInfo; // Create a token credential using the provided username and password TokenCredential userCredentials = await AuthenticationManager.Current.GenerateCredentialAsync (requestInfo.ServiceUri, e.Username, e.Password, requestInfo.GenerateTokenOptions); // Set the task completion source result with the ArcGIS network credential // AuthenticationManager is waiting for this result and will add it to its Credentials collection _loginTaskCompletionSrc.TrySetResult(userCredentials); } catch (Exception ex) { // Unable to create credential, set the exception on the task completion source _loginTaskCompletionSrc.TrySetException(ex); } finally { // Dismiss the login controls Navigation.PopToRootAsync(); } }
private void LoginButtonClick(object sender, EventArgs e) { // Get the values entered in the text fields var username = _usernameTextField.Text.Trim(); var password = _passwordTextField.Text.Trim(); // Make sure the user entered all values if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) { new UIAlertView("Login", "Please enter a username and password", null, "OK", null).Show(); return; } // Fire the OnLoginInfoEntered event and provide the login values if (OnLoginInfoEntered != null) { // Create a new LoginEventArgs to contain the user's values var loginEventArgs = new LoginEventArgs(username, password); // Raise the event OnLoginInfoEntered(sender, loginEventArgs); } }