AndroidSec AndroidSec - 17 days ago 6
Android Question

Android WebView - does it support digest authentication?

I think the title is self explanatory. I can't find any resources or references that mention that digest authentication is supported in WebViews.

A couple of caveats:


  • I'm not talking about basic authentication where the authorisation header is sent with base64 encoding.

  • I'm only talking about WebViews embedded in an application, not simple http requests where apache http client can be used for example.


Answer

You can set one WebViewClient in your WebView and override below method in your WebViewClient, see below code..

private class ExWebChromeClient extends WebViewClient {
    @Override
    public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) {
        super.onReceivedHttpAuthRequest(view, handler, host, realm);    //To change body of overridden methods use File | Settings | File Templates.
    }
}

webView.setWebViewClient(new ExWebChromeClient());//set your Extended WebViewClient here

Here you can show one auth dialog..See showHttpAuthentication method from Android native Browser app here, here one http auth dialog is shown and handled properly inside WebView

Comments