I'm using Moya for iOS networking.
Our server (on a virtual machine) uses OAuth and the requests need to be made with an access token.
I'm trying to retrieve the initial access token with POST /oauth/token
to our endpoint.
What I'm getting back is:
The certificate for this server is invalid. You might be connecting to a server that is pretending to be “xxxxxx” which could put your confidential information at risk." Would you like to connect to the server anyway?
The VM does not validate certificates.
Could this be the issue?
If so, how should Moya be configured to disregard the certificate validation?
If not, any ideas of how to use Moya for this purpose?
Below is the Moya configuration:
enum MyApi {
case auth
}
extension MyApi: TargetType {
var baseURL: URL {
return URL(string: "https://server.nb/api/oauth/token")!
}
var path: String {
return ""
}
var method: Moya.Method {
return .post
}
var sampleData: Data {
return Data()
}
var task: Task {
let params = [
"client_id": "xxxxxxx",
"client_secret": "xxxxxxxx",
"grant_type": "password",
"password": "xxxxxxxx",
"username": "niv@bp.com"
]
return .requestParameters(parameters: params, encoding: URLEncoding.default)
}
var headers: [String : String]? {
let headers = [
"Content-Type": " application/x-www-form-urlencoded",
]
return headers
}
}
EDIT:
This is the info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>https://server.nb</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
</dict>
This is the Moya provider service:
struct MoyaNetworkService {
private let moyaProvider: MoyaProvider<MyApi>!
init(moyaProvider: MoyaProvider<MyApi> = MoyaProvider<MyApi>()) {
self.moyaProvider = moyaProvider
}
func auth() {
moyaProvider.request(.auth) { (result) in
}
}
}