Hello all,
I am relatively new to Swift programming and I'm having trouble understanding how to use Alamofire 5.2 with Digest Authentication specifically using a POST command.
The GET code is quite simple, since one can just add the credential in an authenticate to modify the request on retry. So this works fine:
let user = client_id
let password = client_secret
let credential = URLCredential(user: user, password: password, persistence: .forSession)
AF.request(queues)
.authenticate(with: credential)
.responseJSON { response in
debugPrint(response)
switch response.result {
case let .success(result):
self.presentAlert(title: "Data", message: "Message: \n\n \(result)")
case let .failure(error):
self.presentAlert(title: "Error", message: error.localizedDescription)
}
}
But this is only for a GET request. If I change a request to something like this:
let request = AF.request(
Endpoint.POST.url(),
method: Endpoint.POST.httpMethod,
parameters: userStruct,
encoder: JSONParameterEncoder.default
)
there is not such .authenticate for me to use. In the Basic Authentication construct one can just add it to the header but I'm not aware that I can do this with Digest Auth.
It feels like I should be using a more advanced AF feature/function like RequestInterceptor or RequestModifier but despite having read about them, can't wrap my head around the syntax for what I need to do with my code.
Any advice and especially code specific examples would really help?
Thanks in advance should such help come my way.
Doug