---
title: URLAuthenticationChallenge
framework: foundation
role: symbol
role_heading: Class
path: foundation/urlauthenticationchallenge
---

# URLAuthenticationChallenge

A challenge from a server requiring authentication from the client.

## Declaration

```swift
class URLAuthenticationChallenge
```

## Overview

Overview Your app receives authentication challenges in various URLSession, NSURLConnection, and NSURLDownload delegate methods, such as 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:)](foundation/urlauthenticationchallenge/init(authenticationchallenge:sender:).md)
- [init(protectionSpace:proposedCredential:previousFailureCount:failureResponse:error:sender:)](foundation/urlauthenticationchallenge/init(protectionspace:proposedcredential:previousfailurecount:failureresponse:error:sender:).md)

### Inspecting the authentication challenge

- [protectionSpace](foundation/urlauthenticationchallenge/protectionspace.md)

### Getting properties of previous authentication attempts

- [failureResponse](foundation/urlauthenticationchallenge/failureresponse.md)
- [previousFailureCount](foundation/urlauthenticationchallenge/previousfailurecount.md)
- [proposedCredential](foundation/urlauthenticationchallenge/proposedcredential.md)

### Getting authentication errors

- [error](foundation/urlauthenticationchallenge/error.md)

### Legacy

- [sender](foundation/urlauthenticationchallenge/sender.md)

### Initializers

- [init(coder:)](foundation/urlauthenticationchallenge/init(coder:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Authentication and credentials

- [Handling an authentication challenge](foundation/handling-an-authentication-challenge.md)
- [URLCredential](foundation/urlcredential.md)
- [URLCredentialStorage](foundation/urlcredentialstorage.md)
- [URLProtectionSpace](foundation/urlprotectionspace.md)
