Alamofire: How to attach client certificate in URL?

Created on 5 May 2017  路  5Comments  路  Source: Alamofire/Alamofire

Hello, My web API needs client certificate while requesting from my IOS app (Ex. cert prompt on safari browser). The certificate was pushed by MDM app(A) on my device and it is available under (Settings/General/Device Management/Digital Workspace/certificate) and the same certificate i want to use to make WebAPI request in My App (B) on the same device.

Does it possible? If Yes, How can i achieve using Alamofire?

question

Most helpful comment

We do not have direct support for client certificates in Alamofire at this time. You have a couple options. The first is to set the taskDidReceiveChallenge override closure while the other would be to subclass the SessionDelegate and override the task challenge API.

Once you've done that, you'll need to check for if the challenge's protection space auth method is NSURLAuthenticationMethodClientCertificate. If it is, then you'll need to build a URLCredential from your certificate and pass that off to the completion handler. This thread walks you through the basics.

Best of luck! 馃嵒

All 5 comments

If the certificate was pushed to the device and accepted by the user, it should be part of the default evaluation chain automatically, so Alamofire shouldn't need to do anything. Is that not the case? Note that iOS 10.3 changed the way certificates are accepted by users, so you'll need to make sure it's active.

Hi, I am having similar issue, when I access the API endpoint from iOS safari, it prompts the user for selecting client certificate. But when i call the API endpoint with Alamofire, it simply times out.

We do not have direct support for client certificates in Alamofire at this time. You have a couple options. The first is to set the taskDidReceiveChallenge override closure while the other would be to subclass the SessionDelegate and override the task challenge API.

Once you've done that, you'll need to check for if the challenge's protection space auth method is NSURLAuthenticationMethodClientCertificate. If it is, then you'll need to build a URLCredential from your certificate and pass that off to the completion handler. This thread walks you through the basics.

Best of luck! 馃嵒

Hello @cnoon has direct support been added since 2017?
Is overriding taskDidReceiveChallenge still the goto method here?

Hi @avanarden, using taskDidReceiveChallenge is still the recommended approach.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lvandal picture lvandal  路  3Comments

tib picture tib  路  3Comments

dpstart picture dpstart  路  3Comments

simonliotier picture simonliotier  路  3Comments

Tulleb picture Tulleb  路  3Comments