iosauthenticationbasic-authentication

WKWebView or WebView : How to render a basic auth challenge similar to how Safari does?


I've searched and have not found any answer that doesn't involved handling the credentials in webView(_:didReceive:completionHandler:)

My goal is to render the same auth challenge that occurs in Safari or any other browser so that my code doesn't have to touch the user's credentials.

You can see a sample challenge by visiting https://httpbin.org/basic-auth/username/password in any browser

Is this even possible?

For clarity: If you visit the link above in a normal browser, an auth challenge is displayed/rendered. If you do so in a WKWebView, nothing is displayed. You sit at a white screen.

I'm trying to determine the difference in those behaviors, such as why is it rendered in a normal browser but not web view? Is it the browser that renders the challenge, or is it part of the web content of the URL being visited?

Finally, can Basic Auth be done in WKWebView (or WebView) in such a way as my code doesn't touch the user credentials, because it's the web server handling it via the content displayed in those views?


Solution

  • As suggested by @Paulw11, SFSafariViewController is the answer.