2

I have this code:

func loginWithBasicAuth() -> Void {

    let usernameText = username.text
    let passwordText = password.text

    let credentialData = "\(usernameText):\(passwordText)".dataUsingEncoding(NSUTF8StringEncoding)
    let base64Credentials = credentialData?.base64EncodedStringWithOptions([])
    let headers = ["Authorization": "HTTP Basic \(base64Credentials)"]

    Alamofire.request(.GET, "https://api.domainname.com/v0.1/", headers: headers).responseString { aResponse in

        if let receivedString = aResponse.result.value {

            print(receivedString)

        } else {

            print("Login failed.")

        }
    }
}

In the console it prints:

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802) Login failed.

Here's the configuration in the info.plist file: enter image description here

What's wrong?

Lorenzo
  • 3,293
  • 4
  • 29
  • 56
Bright
  • 5,699
  • 2
  • 50
  • 72

3 Answers3

2

I'm not sure NSThirdPartyExceptionAllowsInsecureHTTPLoads is the right key to use when the connection is via HTTPS. You should probably use NSThirdPartyExceptionMinimumTLSVersion or NSThirdPartyExceptionRequiresForwardSecrecy.

I would highly recommend reading the App Transport Security Technote document, specially the Diagnosing Connection Issues section.

There is a tool that may help you diagnose your domain:

/usr/bin/nscurl --ats-diagnostics [--verbose] URL
Marcos Crispino
  • 8,018
  • 5
  • 41
  • 59
1

Make NSAllowsArbitraryLoads to YES to disable ATS.

Bhavuk Jain
  • 2,167
  • 1
  • 15
  • 23
0

Add NSIncludesSubdomains as you refer to subdomains and wants to have it also as an exception. See this answer for more details

Community
  • 1
  • 1
Julian
  • 9,299
  • 5
  • 48
  • 65