dbconfession
dbconfession

Reputation: 1199

Swift 2 OSX How come session with proxy succeeds without authentication?

I'm making an NSURLRequest through a proxy host/port. It seems that the request is receiving the appropriate response. The only issue is that this proxy/port requires authentication. Why am I not being prompted to authenticate the proxy host?

func sendRequest() {
    let request = NSMutableURLRequest(NSURL(string: "https://www.awebsite/login")
    let params = "&username=\(username)&password=\(password)&okc_api=1"
    request.HTTPBody = params.dataUsingEncoding(NSUTF8StringEncoding)
    request.HTTPMethod = "POST"

    let proxyDict:[NSObject:AnyObject] = [
        kCFNetworkProxiesHTTPEnable: NSNumber(int: 1) as CFNumber,
        kCFStreamPropertyHTTPProxyHost: "123.456.789.012",
        kCFStreamPropertyHTTPProxyPort: 1234,
        kCFStreamPropertyHTTPSProxyHost: "123.456.789.012",
        kCFStreamPropertyHTTPSProxyPort: 1234,
        kCFProxyTypeKey: kCFProxyTypeHTTP,
        kCFProxyTypeKey: kCFProxyTypeHTTPS
    ]

    let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
    configuration.connectionProxyDictionary = proxyDict
    let operationQueue = NSOperationQueue()
    let session = NSURLSession(configuration: configuration, delegate: self, delegateQueue: operationQueue)

    let task = session.dataTaskWithRequest(request) {
        (data, response, error) in
        do {
            let responseHeaders = response as! NSHTTPURLResponse
            let statusCode = responseHeaders.statusCode
            let contentsOfURL = try NSString(contentsOfURL: URL, encoding: NSUTF8StringEncoding)
            if contentsOfURL.containsString("p_home") {
                print(statusCode)
                print("LOGGED IN!")
            } else {
                print("FAILED LOGIN!")
            }
            print(statusCode)
        } catch {
            print(error)
        }
    }
    task.resume()

}

Upvotes: 1

Views: 68

Answers (1)

dgatwood
dgatwood

Reputation: 10407

The proxy's password is probably already stored in the system keychain already, so it isn't asking you again. To know for sure, you'd have to check in the proxy server's logs to see if the requests are coming in with proper authentication.

Upvotes: 1

Related Questions