This repository was archived by the owner on Jul 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Using the SDK with a self signed SSL certificate
Eugeny edited this page Jul 6, 2021
·
1 revision
import Foundation
import ElementsSDK
class CustomURLSessionRequestBuilder<T>: URLSessionRequestBuilder<T> {
required init(method: String, URLString: String, parameters: [String : Any]?, headers: [String : String] = [:]) {
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers)
self.taskDidReceiveChallenge = { _, _, c in (.useCredential, URLCredential(trust: c.protectionSpace.serverTrust!)) }
}
}
class CustomURLSessionDecodableRequestBuilder<T: Decodable>: URLSessionDecodableRequestBuilder<T> {
required init(method: String, URLString: String, parameters: [String : Any]?, headers: [String : String] = [:]) {
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers)
self.taskDidReceiveChallenge = { _, _, c in (.useCredential, URLCredential(trust: c.protectionSpace.serverTrust!)) }
}
}
class CustomURLSessionRequestBuilderFactory: RequestBuilderFactory {
func getNonDecodableBuilder<T>() -> RequestBuilder<T>.Type {
return CustomURLSessionRequestBuilder<T>.self
}
func getBuilder<T: Decodable>() -> RequestBuilder<T>.Type {
return CustomURLSessionDecodableRequestBuilder<T>.self
}
}
ElementsSDKAPI.basePath = ...
ElementsSDKAPI.requestBuilderFactory = CustomURLSessionRequestBuilderFactory()
ElementsSDKAPI.customHeaders = ["Authorization": "Bearer \(...)"]