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

# URLProtectionSpace

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

```
class URLProtectionSpace
```

## 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`](/documentation/Foundation/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

[`-  initWithHost:port:protocol:realm:authenticationMethod:`](/documentation/Foundation/URLProtectionSpace/init(host:port:protocol:realm:authenticationMethod:))

Creates a protection space object from the given host, port, protocol, realm, and authentication method.

[`-  initWithProxyHost:port:type:realm:authenticationMethod:`](/documentation/Foundation/URLProtectionSpace/init(proxyHost:port:type:realm:authenticationMethod:))

Creates a protection space object representing a proxy server.

### Getting protection space properties

[`authenticationMethod`](/documentation/Foundation/URLProtectionSpace/authenticationMethod)

The authentication method used by the receiver.

[`distinguishedNames`](/documentation/Foundation/URLProtectionSpace/distinguishedNames)

The acceptable certificate-issuing authorities for client certificate authentication.

[`host`](/documentation/Foundation/URLProtectionSpace/host)

The receiver’s host.

[`isProxy`](/documentation/Foundation/NSURLProtectionSpace/isProxy)

A Boolean value that indicates whether the receiver represents a proxy server.

[`port`](/documentation/Foundation/URLProtectionSpace/port)

The receiver’s port.

[`protocol`](/documentation/Foundation/URLProtectionSpace/protocol)

The receiver’s protocol.

[`proxyType`](/documentation/Foundation/URLProtectionSpace/proxyType)

The receiver’s proxy type.

[`realm`](/documentation/Foundation/URLProtectionSpace/realm)

The receiver’s authentication realm

[`receivesCredentialSecurely`](/documentation/Foundation/URLProtectionSpace/receivesCredentialSecurely)

A Boolean value that indicates whether the credentials for the protection space can be sent securely.

[`serverTrust`](/documentation/Foundation/URLProtectionSpace/serverTrust)

A representation of the server’s SSL transaction state.

### Identifying protection space properties

[NSURLProtectionSpace protocol types](/documentation/Foundation/nsurlprotectionspace-protocol-types)

These constants describe the supported protocols for a protection space, as returned by [`protocol`](/documentation/Foundation/URLProtectionSpace/protocol).

[NSURLProtectionSpace proxy types](/documentation/Foundation/nsurlprotectionspace-proxy-types)

These constants describe the supported proxy types used in [`init(proxyHost:port:type:realm:authenticationMethod:)`](/documentation/Foundation/URLProtectionSpace/init(proxyHost:port:type:realm:authenticationMethod:)) and returned by [`proxyType`](/documentation/Foundation/URLProtectionSpace/proxyType).

[NSURLProtectionSpace authentication method constants](/documentation/Foundation/nsurlprotectionspace-authentication-method-constants)

Constants describing known values of the [`authenticationMethod`](/documentation/Foundation/URLProtectionSpace/authenticationMethod) property of a [`URLProtectionSpace`](/documentation/Foundation/URLProtectionSpace).

## Relationships

### Conforms To

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`NSCopying`](/documentation/Foundation/NSCopying)

[`CVarArg`](/documentation/Swift/CVarArg)

[`Sendable`](/documentation/Swift/Sendable)

[`Equatable`](/documentation/Swift/Equatable)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`Hashable`](/documentation/Swift/Hashable)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)