Created
December 6, 2018 15:37
-
-
Save ozkary/5491406e97c6b1018ebaac0935728e2c to your computer and use it in GitHub Desktop.
In order to write a handler for the challenge-response event, we need to extend the WebViewClient class. We start by implementing a constructor that can take the credential information. This enables the activity that instantiates our class to manage the credential information and just pass it to our class during the class instantiation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| internal class AuthWebViewClient : WebViewClient | |
| { | |
| public string Username { get; } | |
| public string Password { get; } | |
| private int LoginCount = 0; | |
| /// <summary> | |
| /// gets the user credentials for the impersonation process | |
| /// </summary> | |
| /// <param name="username"></param> | |
| /// <param name="password"></param> | |
| public AuthWebViewClient(string username, string password) | |
| { | |
| Username = username; | |
| Password = password; | |
| } | |
| /// <summary> | |
| /// handles the authentication with the website. | |
| /// </summary> | |
| /// <param name="view"></param> | |
| /// <param name="handler"></param> | |
| /// <param name="host"></param> | |
| /// <param name="realm"></param> | |
| /// <remarks> | |
| /// </remarks> | |
| public override void OnReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, string host, string realm) | |
| { | |
| try | |
| { | |
| if (LoginCount < 3) | |
| { | |
| LoginCount++; | |
| handler.Proceed(Username, Password); | |
| } | |
| else | |
| { | |
| LoginCount = 0; | |
| handler.Cancel(); | |
| } | |
| } | |
| catch (Exception ex) | |
| { | |
| Toast.MakeText(Application.Context, ex.Message, ToastLength.Long).Show(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment