---
title: "init(authenticationChallenge:sender:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/urlauthenticationchallenge/init(authenticationchallenge:sender:)"
---

# init(authenticationChallenge:sender:)

Creates an authentication challenge from an existing challenge instance.

## Declaration

```swift
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 doc://com.apple.foundation/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 doc://com.apple.foundation/documentation/Foundation/URLProtocol subclass that called this method.

## Return Value

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

## Discussion

Discussion Most apps don’t create URLAuthenticationChallenge instances themselves. Instead, they handle received challenges in the urlSession(_:task:didReceive:completionHandler:) method of URLSessionTaskDelegate. However, you might need to create authentication challenge objects when adding support for custom networking protocols, as part of a custom URLProtocol subclass. When you subclass an existing URLProtocol subclass, this initializer lets you modify challenges issued by the existing class so that your subclass receives any responses to those challenges.

## See Also

### Creating an authentication challenge instance

- [init(protectionSpace:proposedCredential:previousFailureCount:failureResponse:error:sender:)](foundation/urlauthenticationchallenge/init(protectionspace:proposedcredential:previousfailurecount:failureresponse:error:sender:).md)
