title: WKWebView Authorization
body: <p>I am would like open a website, using a password/username (basic)Authorization in a WKWebView.<br>
  To do that I use the method <code>didReceiveAuthenticationChallenge</code>.</p>
  
  <pre><code>import UIKit
  import WebKit
  
  class ViewController: UIViewController {
  
  @IBOutlet weak var container: UIView!
  var webView: WKWebView!
  
  override func viewDidLoad() {
      super.viewDidLoad()
      webView = WKWebView()
      container.addSubview(webView)
      let urlStr = "https://vplan.bielefeld-marienschule.logoip.de/subst_002.htm"
      let url = NSURL(string: urlStr)!
      let request = NSURLRequest(url: url as URL)
      webView.load(request as URLRequest)
  }
  func webView(webView: WKWebView, didReceiveAuthenticationChallenge challenge: URLAuthenticationChallenge, completionHandler: (URLSession.AuthChallengeDisposition, URLCredential?) -&gt; Void){
      if challenge.protectionSpace.host == "https://vplan.bielefeld-marienschule.logoip.de/subst_002.htm" {
          let userStr = "********"
          let passwordStr = "********"
          let credential = URLCredential(user: userStr, password: passwordStr, persistence: URLCredential.Persistence.forSession)
          challenge.sender?.use(credential, for: challenge)
          completionHandler(.useCredential, credential)
      }
  }
  
  override func viewDidAppear(_ animated: Bool) {
      let frame = CGRect(x: 0, y: 0, width: container.bounds.width, height: container.bounds.height)
      webView.frame = frame
  </code></pre>
  
  <p>But for some reason, it does not work.<br>
  Adding the code line     </p>
  
  <pre><code>completionHandler(URLSession.AuthChallengeDisposition.UseCredential, credential)
  </code></pre>
  
  <p>like in the description here: <a href="https://stackoverflow.com/questions/37177751/authentication-with-wkwebview-in-swift">Authentication with WKWebView in Swift</a> produced an error.<br>
  I have also tried to change the <code>challenge.protectionSpace.host</code> into <code>vplan.bielefeld-marienschule.logoip.de:443</code> which is shown as the login adress in the  <a href="https://i.stack.imgur.com/6Uttd.png" rel="nofollow noreferrer">Safari pop-up</a> and into the IP-Adress of the server (93.206.31.253).</p>
  
  <p>Hope you can help me.
  Thank You!</p>