// AuthenticationManager.ChallengeHandler function that prompts the user for login information to create a credential private async Task <Credential> CreateCredentialAsync(CredentialRequestInfo info) { // See if authentication is already in process if (_loginTaskCompletionSrc != null) { return(null); } // Create a new TaskCompletionSource for the login operation // (passing the CredentialRequestInfo object to the constructor will make it available from its AsyncState property) _loginTaskCompletionSrc = new TaskCompletionSource <Credential>(info); // Create a dialog (fragment) with login controls LoginDialogFragment enterLoginDialog = new LoginDialogFragment(); // Handle the login and the cancel events enterLoginDialog.OnLoginClicked += LoginClicked; enterLoginDialog.OnLoginCanceled += (s, e) => { _loginTaskCompletionSrc.TrySetCanceled(); _loginTaskCompletionSrc = null; }; // Begin a transaction to show a UI fragment (the login dialog) FragmentTransaction transax = FragmentManager.BeginTransaction(); enterLoginDialog.Show(transax, "login"); // Return the login task, the result will be ready when completed (user provides login info and clicks the "Login" button) return(await _loginTaskCompletionSrc.Task); }
// AuthenticationManager.ChallengeHandler function that prompts the user for login information to create a credential private async Task<Credential> CreateCredentialAsync(CredentialRequestInfo info) { // See if authentication is already in process if (_loginTaskCompletionSrc != null) { return null; } // Create a new TaskCompletionSource for the login operation // (passing the CredentialRequestInfo object to the constructor will make it available from its AsyncState property) _loginTaskCompletionSrc = new TaskCompletionSource<Credential>(info); // Create a dialog (fragment) with login controls LoginDialogFragment enterLoginDialog = new LoginDialogFragment(); // Handle the login and the cancel events enterLoginDialog.OnLoginClicked += LoginClicked; enterLoginDialog.OnLoginCanceled += (s, e) => { _loginTaskCompletionSrc.TrySetCanceled(); _loginTaskCompletionSrc = null; }; // Begin a transaction to show a UI fragment (the login dialog) FragmentTransaction transax = FragmentManager.BeginTransaction(); enterLoginDialog.Show(transax, "login"); // Return the login task, the result will be ready when completed (user provides login info and clicks the "Login" button) return await _loginTaskCompletionSrc.Task; }