---
title: "init(identity:certificates:persistence:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/urlcredential/init(identity:certificates:persistence:)"
---

# init(identity:certificates:persistence:)

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

## Declaration

```swift
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 doc://com.apple.foundation/documentation/Foundation/URLCredential/Persistence-swift.enum/forSession because that most accurately reflects the actual behaviour.

## Return Value

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

## Discussion

Discussion When you receive a client certificate authentication challenge (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.

## See Also

### Creating a credential

- [init(forTrust:)](foundation/urlcredential/init(fortrust:).md)
- [init(trust:)](foundation/urlcredential/init(trust:).md)
- [init(user:password:persistence:)](foundation/urlcredential/init(user:password:persistence:).md)
- [URLCredential.Persistence](foundation/urlcredential/persistence-swift.enum.md)
