---
title: URLProtectionSpace
framework: foundation
role: symbol
role_heading: Class
path: foundation/urlprotectionspace
---

# URLProtectionSpace

A server or an area on a server, commonly referred to as a realm, that requires authentication.

## Declaration

```swift
class URLProtectionSpace
```

## Overview

Overview A protection space defines a series of matching constraints that determine which credential should be provided. For example, if a request provides your delegate with a URLAuthenticationChallenge object that requests a client username and password, your app should provide the correct username and password for the particular host, port, protocol, and realm, as specified in the challenge’s protection space. note: This class has no designated initializer; its init method always returns nil. You must initialize this class by calling one of the initialization methods described in Creating a protection space.

## Topics

### Creating a protection space

- [init(host:port:protocol:realm:authenticationMethod:)](foundation/urlprotectionspace/init(host:port:protocol:realm:authenticationmethod:).md)
- [init(proxyHost:port:type:realm:authenticationMethod:)](foundation/urlprotectionspace/init(proxyhost:port:type:realm:authenticationmethod:).md)

### Getting protection space properties

- [authenticationMethod](foundation/urlprotectionspace/authenticationmethod.md)
- [distinguishedNames](foundation/urlprotectionspace/distinguishednames.md)
- [host](foundation/urlprotectionspace/host.md)
- [port](foundation/urlprotectionspace/port.md)
- [protocol](foundation/urlprotectionspace/protocol.md)
- [proxyType](foundation/urlprotectionspace/proxytype.md)
- [realm](foundation/urlprotectionspace/realm.md)
- [receivesCredentialSecurely](foundation/urlprotectionspace/receivescredentialsecurely.md)
- [serverTrust](foundation/urlprotectionspace/servertrust.md)

### Identifying protection space properties

- [NSURLProtectionSpace protocol types](foundation/nsurlprotectionspace-protocol-types.md)
- [NSURLProtectionSpace proxy types](foundation/nsurlprotectionspace-proxy-types.md)
- [NSURLProtectionSpace authentication method constants](foundation/nsurlprotectionspace-authentication-method-constants.md)

### Initializers

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

### Instance Methods

- [isProxy()](foundation/urlprotectionspace/isproxy().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)
- [NSCopying](foundation/nscopying.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)
- [URLAuthenticationChallenge](foundation/urlauthenticationchallenge.md)
- [URLCredential](foundation/urlcredential.md)
- [URLCredentialStorage](foundation/urlcredentialstorage.md)
