<!--
{
  "availability" : [
    "iOS: 3.0.0 - 8.0.0",
    "iPadOS: 3.0.0 - 8.0.0",
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.6.0 - 10.10.0",
    "tvOS: 9.0.0 - 9.0.0",
    "visionOS: 1.0.0 - 1.0.0",
    "watchOS: 2.0.0 - 2.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSURLConnectionDelegate/connection(_:canAuthenticateAgainstProtectionSpace:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(pl)NSURLConnectionDelegate(im)connection:canAuthenticateAgainstProtectionSpace:"
  },
  "title" : "connection(_:canAuthenticateAgainstProtectionSpace:)"
}
-->

# connection(_:canAuthenticateAgainstProtectionSpace:)

Sent to determine whether the delegate is able to respond to a protection space’s form of authentication.

```
optional func connection(_ connection: NSURLConnection, canAuthenticateAgainstProtectionSpace protectionSpace: URLProtectionSpace) -> Bool
```

## Parameters

`connection`

The connection sending the message.

`protectionSpace`

The protection space that generates an authentication challenge.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if the delegate if able to respond to a protection space’s form of authentication, otherwise <doc://com.apple.documentation/documentation/Swift/false>.

## Discussion

This method is called before [`connection(_:didReceive:)`](/documentation/Foundation/NSURLConnectionDelegate/connection(_:didReceive:)), allowing the delegate to inspect a protection space before attempting to authenticate against it. By returning <doc://com.apple.documentation/documentation/Swift/true>, the delegate indicates that it can handle the form of authentication, which it does in the subsequent call to [`connection(_:didReceive:)`](/documentation/Foundation/NSURLConnectionDelegate/connection(_:didReceive:)). If the delegate returns <doc://com.apple.documentation/documentation/Swift/false>, the system attempts to use the user’s keychain to authenticate. If your delegate does not implement this method and the protection space uses client certificate authentication or server trust authentication, the system behaves as if you returned <doc://com.apple.documentation/documentation/Swift/false>. The system behaves as if you returned <doc://com.apple.documentation/documentation/Swift/true> for all other authentication methods.

> Note:
> This method is not called if the delegate implements the ``doc://com.apple.foundation/documentation/Foundation/NSURLConnectionDelegate/connection(_:willSendRequestFor:)`` method.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)