HAURLSessionDelegate

public class HAURLSessionDelegate : NSObject, URLSessionDelegate

URLSession delegate for HAKit REST API calls that supports custom certificate handling

This delegate handles both client certificate authentication (mTLS) and custom server certificate validation through the HACertificateProvider protocol.

Example usage:

struct MyCertificateProvider: HACertificateProvider {
    func provideClientCertificate(for challenge: ...) {
        // Provide client certificate from keychain
    }

    func evaluateServerTrust(_ serverTrust: ...) {
        // Validate self-signed or custom CA certificates
    }
}

let provider = MyCertificateProvider()
let delegate = HAURLSessionDelegate(certificateProvider: provider)
let session = URLSession(configuration: .ephemeral, delegate: delegate, delegateQueue: nil)
let connection = HAKit.connection(configuration: config, urlSession: session)
  • Initialize with a certificate provider

    Declaration

    Swift

    public init(certificateProvider: HACertificateProvider)

    Parameters

    certificateProvider

    The provider that handles certificate authentication

  • Undocumented

    Declaration

    Swift

    public func urlSession(
        _ session: URLSession,
        didReceive challenge: URLAuthenticationChallenge,
        completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void
    )