<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.2.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URLAuthenticationChallenge/init(authenticationChallenge:sender:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURLAuthenticationChallenge(im)initWithAuthenticationChallenge:sender:"
  },
  "title" : "init(authenticationChallenge:sender:)"
}
-->

# init(authenticationChallenge:sender:)

Creates an authentication challenge from an existing challenge instance.

```
init(authenticationChallenge challenge: URLAuthenticationChallenge, sender: any URLAuthenticationChallengeSender)
```

## Parameters

`challenge`

The challenge that you want to copy. Usually, this is a challenge received by an existing [`URLProtocol`](/documentation/Foundation/URLProtocol) subclass that you are subclassing.

`sender`

The sender that you want to use for the new object. Typically, the sender is the instance of your custom [`URLProtocol`](/documentation/Foundation/URLProtocol) subclass that called this method.

## Return Value

A new authentication challenge object, based on an existing challenge.

## Discussion

Most apps don’t create [`URLAuthenticationChallenge`](/documentation/Foundation/URLAuthenticationChallenge) instances themselves. Instead, they handle received challenges in the [`urlSession(_:task:didReceive:completionHandler:)`](/documentation/Foundation/URLSessionTaskDelegate/urlSession(_:task:didReceive:completionHandler:)) method of [`URLSessionTaskDelegate`](/documentation/Foundation/URLSessionTaskDelegate).

However, you might need to create authentication challenge objects when adding support for custom networking protocols, as part of a custom [`URLProtocol`](/documentation/Foundation/URLProtocol) subclass. When you subclass an existing [`URLProtocol`](/documentation/Foundation/URLProtocol) subclass, this initializer lets you modify challenges issued by the existing class so that your subclass receives any responses to those challenges.

---

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)