<!--
{
  "availability" : [
    "iOS: 3.0.0 -",
    "iPadOS: 3.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.6.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URLCredential/init(identity:certificates:persistence:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURLCredential(im)initWithIdentity:certificates:persistence:"
  },
  "title" : "init(identity:certificates:persistence:)"
}
-->

# init(identity:certificates:persistence:)

Creates a URL credential instance for resolving a client certificate authentication challenge.

```
init(identity: SecIdentity, certificates certArray: [Any]?, persistence: URLCredential.Persistence)
```

## Parameters

`identity`

The identity for the credential.

`certArray`

An array of one or more `SecCertificateRef` objects representing intermediate certificates leading from the identity’s certificate to a trusted root, or `nil` if the server does not need any intermediate certificates to authenticate the client.

`persistence`

The method ignores this parameter; you should supply a value of [`URLCredential.Persistence.forSession`](/documentation/Foundation/URLCredential/Persistence-swift.enum/forSession) because that most accurately reflects the actual behaviour.

## Return Value

A new URL credential object, using the provided identity and, optionally, an array of intermediate certificates.

## Discussion

When you receive a client certificate authentication challenge ([`NSURLAuthenticationMethodClientCertificate`](/documentation/Foundation/NSURLAuthenticationMethodClientCertificate)) and want to resolve it successfully, you must supply a credential created using this initializer.

In most cases you should pass `nil` to the `certArray` parameter. You only need to supply an array of intermediate certificates if the server needs those intermediate certificates to authenticate the client. Typically this isn’t necessary because the server already has a copy of the relevant intermediate certificates.

---

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)