---
title: "connection(_:canAuthenticateAgainstProtectionSpace:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsurlconnectiondelegate/connection(_:canauthenticateagainstprotectionspace:)"
---

# connection(_:canAuthenticateAgainstProtectionSpace:)

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

## Declaration

```swift
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

Return Value true if the delegate if able to respond to a protection space’s form of authentication, otherwise false.

## Discussion

Discussion This method is called before connection(_:didReceive:), allowing the delegate to inspect a protection space before attempting to authenticate against it. By returning true, the delegate indicates that it can handle the form of authentication, which it does in the subsequent call to connection(_:didReceive:). If the delegate returns 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 false. The system behaves as if you returned true for all other authentication methods. note: This method is not called if the delegate implements the connection(_:willSendRequestFor:) method.

## See Also

### Connection Authentication

- [connection(_:willSendRequestFor:)](foundation/nsurlconnectiondelegate/connection(_:willsendrequestfor:).md)
- [connection(_:didCancel:)](foundation/nsurlconnectiondelegate/connection(_:didcancel:).md)
- [connection(_:didReceive:)](foundation/nsurlconnectiondelegate/connection(_:didreceive:).md)
- [connectionShouldUseCredentialStorage(_:)](foundation/nsurlconnectiondelegate/connectionshouldusecredentialstorage(_:).md)
