Mac Developer Library

Developer

Foundation Framework Reference NSURLProtectionSpace Class Reference

Options
Deployment Target:

On This Page
Language:

NSURLProtectionSpace

An NSURLProtectionSpace object represents a server or an area on a server, commonly referred to as a realm, that requires authentication. The protection space defines a series of matching constraints that determine which credential should be provided.

For example, if a request provides your delegate with an NSURLAuthenticationChallenge 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.

Inheritance


Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in OS X v10.2 with Safari 1.0 installed.
Available in OS X v10.2.7 and later.
  • Initializes a protection space object.

    Declaration

    Swift

    init(host host: String, port port: Int, `protocol` `protocol`: String?, realm realm: String?, authenticationMethod authenticationMethod: String?)

    Objective-C

    - (instancetype)initWithHost:(NSString *)host port:(NSInteger)port protocol:(NSString *)protocol realm:(NSString *)realm authenticationMethod:(NSString *)authenticationMethod

    Parameters

    host

    The host name for the protection space object.

    port

    The port for the protection space object. If port is 0 the default port for the specified protocol is used, for example, port 80 for HTTP. Note that servers can, and do, treat these values differently.

    protocol

    The protocol for the protection space object. The value of protocol is equivalent to the scheme for a URL in the protection space, for example, “http”, “https”, “ftp”, etc.

    realm

    A string indicating a protocol specific subdivision of the host. realm may be nil if there is no specified realm or if the protocol doesn’t support realms.

    authenticationMethod

    The type of authentication to use. authenticationMethod should be set to one of the values in NSURLProtectionSpace Authentication Methods or nil to use the default, NSURLAuthenticationMethodDefault.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 with Safari 1.0 installed.

    Available in OS X v10.2.7 and later.

  • Initializes a protection space object representing a proxy server.

    Declaration

    Swift

    init(proxyHost host: String, port port: Int, type proxyType: String?, realm realm: String?, authenticationMethod authenticationMethod: String?)

    Objective-C

    - (instancetype)initWithProxyHost:(NSString *)host port:(NSInteger)port type:(NSString *)proxyType realm:(NSString *)realm authenticationMethod:(NSString *)authenticationMethod

    Parameters

    host

    The host of the proxy server for the protection space object.

    port

    The port for the protection space object. If port is 0 the default port for the specified proxy type is used, for example, port 80 for HTTP. Note that servers can, and do, treat these values differently.

    proxyType

    The type of proxy server. The value of proxyType should be set to one of the values specified in NSURLProtectionSpace Proxy Types.

    realm

    A string indicating a protocol specific subdivision of the host. realm may be nil if there is no specified realm or if the protocol doesn’t support realms.

    authenticationMethod

    The type of authentication to use. authenticationMethod should be set to one of the values in NSURLProtectionSpace Authentication Methods or nil to use the default, NSURLAuthenticationMethodDefault.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 with Safari 1.0 installed.

    Available in OS X v10.2.7 and later.

  • The authentication method used by the receiver. (read-only)

    Declaration

    Swift

    var authenticationMethod: String? { get }

    Objective-C

    @property(readonly, copy) NSString *authenticationMethod

    Discussion

    The supported authentication methods are listed in NSURLProtectionSpace Authentication Methods.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 with Safari 1.0 installed.

    Available in OS X v10.2.7 and later.

  • The acceptable certificate-issuing authorities for client certificate authentication. (read-only)

    Declaration

    Swift

    var distinguishedNames: [AnyObject]? { get }

    Objective-C

    @property(readonly, copy) NSArray *distinguishedNames

    Discussion

    nil if the authentication method of the protection space is not client certificate. The returned issuing authorities are encoded with Distinguished Encoding Rules (DER).

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.6 and later.

  • host host Property

    The receiver’s host. (read-only)

    Declaration

    Swift

    var host: String { get }

    Objective-C

    @property(readonly, copy) NSString *host

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 with Safari 1.0 installed.

    Available in OS X v10.2.7 and later.

  • isProxy isProxy Property

    A boolean value that indicates whether the receiver represents a proxy server. (read-only)

    Declaration

    Objective-C

    @property(readonly) BOOL isProxy

    Discussion

    YEStrue if the receiver represents a proxy server, NOfalse otherwise.

    Import Statement

    Objective-C

    @import Foundation;

    Availability

    Available in OS X v10.2 with Safari 1.0 installed.

    Available in OS X v10.2.7 and later.

  • port port Property

    The receiver’s port. (read-only)

    Declaration

    Swift

    var port: Int { get }

    Objective-C

    @property(readonly) NSInteger port

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 with Safari 1.0 installed.

    Available in OS X v10.2.7 and later.

  • protocol protocol Property

    The receiver’s protocol. (read-only)

    Declaration

    Swift

    var `protocol`: String? { get }

    Objective-C

    @property(readonly, copy) NSString *protocol

    Discussion

    nil if the receiver represents a proxy protection space.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 with Safari 1.0 installed.

    Available in OS X v10.2.7 and later.

  • proxyType proxyType Property

    The receiver's proxy type. (read-only)

    Declaration

    Swift

    var proxyType: String? { get }

    Objective-C

    @property(readonly, copy) NSString *proxyType

    Discussion

    The receiver's proxy type, or nil if the receiver does not represent a proxy protection space. The supported proxy types are listed in NSURLProtectionSpace Proxy Types.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 with Safari 1.0 installed.

    Available in OS X v10.2.7 and later.

  • realm realm Property

    The receiver’s authentication realm (read-only)

    Declaration

    Swift

    var realm: String? { get }

    Objective-C

    @property(readonly, copy) NSString *realm

    Discussion

    nil if no realm has been set. A realm is generally only specified for HTTP and HTTPS authentication.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 with Safari 1.0 installed.

    Available in OS X v10.2.7 and later.

  • A boolean value that indicates whether the credentials for the protection space can be sent securely. (read-only)

    Declaration

    Swift

    var receivesCredentialSecurely: Bool { get }

    Objective-C

    @property(readonly) BOOL receivesCredentialSecurely

    Discussion

    YEStrue if the credentials for the protection space represented by the receiver can be sent securely, NOfalse otherwise.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.2 with Safari 1.0 installed.

    Available in OS X v10.2.7 and later.

  • A representation of the server’s SSL transaction state. (read-only)

    Declaration

    Swift

    var serverTrust: SecTrust? { get }

    Objective-C

    @property(readonly) SecTrustRef serverTrust

    Discussion

    nil if the authentication method of the protection space is not server trust.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.6 and later.

  • These constants describe the supported protocols for a protection space, as returned by protocol.

    Declaration

    Swift

    let NSURLProtectionSpaceHTTP: NSString! let NSURLProtectionSpaceHTTPS: NSString! let NSURLProtectionSpaceFTP: NSString!

    Objective-C

    NSString * const NSURLProtectionSpaceHTTP; NSString * const NSURLProtectionSpaceHTTPS; NSString * const NSURLProtectionSpaceFTP;

    Constants

    • NSURLProtectionSpaceHTTP

      NSURLProtectionSpaceHTTP

      The protocol type for HTTP.

      Available in OS X v10.5 and later.

    • NSURLProtectionSpaceHTTPS

      NSURLProtectionSpaceHTTPS

      The protocol type for HTTPS.

      Available in OS X v10.5 and later.

    • NSURLProtectionSpaceFTP

      NSURLProtectionSpaceFTP

      The protocol type for FTP.

      Available in OS X v10.5 and later.

  • These constants describe the supported proxy types used in initWithProxyHost:port:type:realm:authenticationMethod: and returned by proxyType.

    Declaration

    Swift

    let NSURLProtectionSpaceHTTPProxy: NSString! let NSURLProtectionSpaceHTTPSProxy: NSString! let NSURLProtectionSpaceFTPProxy: NSString! let NSURLProtectionSpaceSOCKSProxy: NSString!

    Objective-C

    NSString *NSURLProtectionSpaceHTTPProxy; NSString *NSURLProtectionSpaceHTTPSProxy; NSString *NSURLProtectionSpaceFTPProxy; NSString *NSURLProtectionSpaceSOCKSProxy;

    Constants

    • NSURLProtectionSpaceHTTPProxy

      NSURLProtectionSpaceHTTPProxy

      The proxy type for HTTP proxies.

      Available in OS X v10.2 and later.

    • NSURLProtectionSpaceHTTPSProxy

      NSURLProtectionSpaceHTTPSProxy

      The proxy type for HTTPS proxies.

      Available in OS X v10.2 and later.

    • NSURLProtectionSpaceFTPProxy

      NSURLProtectionSpaceFTPProxy

      The proxy type for FTP proxies.

      Available in OS X v10.2 and later.

    • NSURLProtectionSpaceSOCKSProxy

      NSURLProtectionSpaceSOCKSProxy

      The proxy type for SOCKS proxies.

      Available in OS X v10.2 and later.

    Availability

    Available in OS X v10.2 with Safari 1.0 installed.

    Available in OS X v10.2.7 and later.

  • These constants describe the available authentication methods used in initWithHost:port:protocol:realm:authenticationMethod:, initWithProxyHost:port:type:realm:authenticationMethod: and returned by authenticationMethod.

    Declaration

    Swift

    let NSURLAuthenticationMethodDefault: NSString! let NSURLAuthenticationMethodHTTPBasic: NSString! let NSURLAuthenticationMethodHTTPDigest: NSString! let NSURLAuthenticationMethodHTMLForm: NSString! let NSURLAuthenticationMethodNegotiate: NSString! let NSURLAuthenticationMethodNTLM: NSString! let NSURLAuthenticationMethodClientCertificate: NSString! let NSURLAuthenticationMethodServerTrust: NSString!

    Objective-C

    NSString *NSURLAuthenticationMethodDefault; NSString *NSURLAuthenticationMethodHTTPBasic; NSString *NSURLAuthenticationMethodHTTPDigest; NSString *NSURLAuthenticationMethodHTMLForm; NSString *NSURLAuthenticationMethodNegotiate; NSString *NSURLAuthenticationMethodNTLM; NSString *NSURLAuthenticationMethodClientCertificate; NSString *NSURLAuthenticationMethodServerTrust;

    Constants

    • NSURLAuthenticationMethodDefault

      NSURLAuthenticationMethodDefault

      Use the default authentication method for a protocol.

      Available in OS X v10.2 and later.

    • NSURLAuthenticationMethodHTTPBasic

      NSURLAuthenticationMethodHTTPBasic

      Use HTTP basic authentication for this protection space.

      This is equivalent to NSURLAuthenticationMethodDefault for HTTP.

      Available in OS X v10.2 and later.

    • NSURLAuthenticationMethodHTTPDigest

      NSURLAuthenticationMethodHTTPDigest

      Use HTTP digest authentication for this protection space.

      Available in OS X v10.2 and later.

    • NSURLAuthenticationMethodHTMLForm

      NSURLAuthenticationMethodHTMLForm

      Use HTML form authentication for this protection space.

      The URL loading system never issues authentication challenges based on this authentication method. However, if your app authenticates by submitting a web form (or in some other protocol-neutral way), you can specify this protection space when you persist or look up credentials using the NSURLCredentialStorage class.

      Available in OS X v10.2 and later.

    • NSURLAuthenticationMethodNegotiate

      NSURLAuthenticationMethodNegotiate

      Negotiate whether to use Kerberos or NTLM authentication for this protection space.

      Available in OS X v10.5 and later.

    • NSURLAuthenticationMethodNTLM

      NSURLAuthenticationMethodNTLM

      Use NTLM authentication for this protection space.

      Available in OS X v10.5 and later.

    • NSURLAuthenticationMethodClientCertificate

      NSURLAuthenticationMethodClientCertificate

      Use client certificate authentication for this protection space.

      This authentication method can apply to any protocol.

      Available in OS X v10.6 and later.

    • NSURLAuthenticationMethodServerTrust

      NSURLAuthenticationMethodServerTrust

      Perform server trust authentication (certificate validation) for this protection space.

      This authentication method can apply to any protocol, and is most commonly used for overriding SSL and TLS chain validation.

      To learn more, read Performing Authentication and Customizing Server Certificate Validation.

      Available in OS X v10.6 and later.

    Availability

    Available in OS X v10.2 with Safari 1.0 installed.

    Available in OS X v10.2.7 and later.