<!--
{
  "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",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURLAuthenticationChallenge"
  },
  "title" : "URLAuthenticationChallenge"
}
-->

# URLAuthenticationChallenge

A challenge from a server requiring authentication from the client.

```
class URLAuthenticationChallenge
```

## Overview

Your app receives authentication challenges in various [`URLSession`](/documentation/Foundation/URLSession), [`NSURLConnection`](/documentation/Foundation/NSURLConnection), and [`NSURLDownload`](/documentation/Foundation/NSURLDownload) delegate methods, such as [`urlSession(_:task:didReceive:completionHandler:)`](/documentation/Foundation/URLSessionTaskDelegate/urlSession(_:task:didReceive:completionHandler:)). These objects provide the information you’ll need when deciding how to handle a server’s request for authentication.

At the core of that authentication challenge is a *protection space* that defines the type of authentication being requested, the host and port number, the networking protocol, and (where applicable) the authentication realm (a group of related URLs on the same server that share a single set of credentials).

## Topics

### Creating an authentication challenge instance

[`init(authenticationChallenge:sender:)`](/documentation/Foundation/URLAuthenticationChallenge/init(authenticationChallenge:sender:))

Creates an authentication challenge from an existing challenge instance.

[`init(protectionSpace:proposedCredential:previousFailureCount:failureResponse:error:sender:)`](/documentation/Foundation/URLAuthenticationChallenge/init(protectionSpace:proposedCredential:previousFailureCount:failureResponse:error:sender:))

Initializes an authentication challenge from parameters you provide.

### Inspecting the authentication challenge

[`protectionSpace`](/documentation/Foundation/URLAuthenticationChallenge/protectionSpace)

The receiver’s protection space.

### Getting properties of previous authentication attempts

[`failureResponse`](/documentation/Foundation/URLAuthenticationChallenge/failureResponse)

The URL response object representing the last authentication failure.

[`previousFailureCount`](/documentation/Foundation/URLAuthenticationChallenge/previousFailureCount)

The receiver’s count of failed authentication attempts.

[`proposedCredential`](/documentation/Foundation/URLAuthenticationChallenge/proposedCredential)

The proposed credential for this challenge.

### Getting authentication errors

[`error`](/documentation/Foundation/URLAuthenticationChallenge/error)

The error object representing the last authentication failure.

### Legacy

[`sender`](/documentation/Foundation/URLAuthenticationChallenge/sender)

The sender of the challenge.



---

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)