0

I have one piece of python code that need to transfer into swift code. I see lots of example using URLSessionDelegate and URLCerdentital. I see the signure for URLCredential is .init(identity: <#T##SecIdentity#>, certificates: <#T##[Any]?#>, persistence: <#T##URLCredential.Persistence#>) for URLCredential. For me, how can I pass the identity part if I have two file path?

cert_file_path = "cert.pem"
key_file_path = "key.pem"
import requests
cert_file_path = "cert.pem"
key_file_path = "key.pem"

url = "https://example.com/resource"
params = {"param_1": "value_1", "param_2": "value_2"}
cert = (cert_file_path, key_file_path)
r = requests.get(url, params=params, cert=cert)
jacobcan118
  • 7,797
  • 12
  • 50
  • 95

1 Answers1

0

First, add the identity into the keychain:

How to establish a SecIdentityRef in an iPhone keychain ? (Without a .p12)

by adding the private key and then adding the certificates.

Then pull the SecIdentityRef out of the keychain and use it to create a credential by using NSURLCredential's credentialWithIdentity:certificates:persistence: class method.

dgatwood
  • 10,129
  • 1
  • 28
  • 49