I would like to make an authentication challenge to the browser (Safari) to allow users log in my application.
What I am doing actually in my API is to save a cookie in the browser to persist session. Is it possible to request the cookie from my app?
Thank you in advance
For web based client authentication challenges, HTTP Basic or Client Certificate, in a native app you could look at using WKWebView. For example, the following is certainly not exhaustive but should get you going:I would like to make an authentication challenge to the browser (Safari) to allow users log in my application.
Code Block swift func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) { if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust { /* Evaluate Server Trust etc.. */ } else if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodHTTPBasic { /* HTTP Basic */ } else if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodClientCertificate { /* Client Certificate */ } else { /* Default fallback */ completionHandler(.performDefaultHandling, nil) } }
Depending upon your use case here, ASWebAuthenticationSession might be what you are looking for with first party cookies, or better yet, a token based authentication mechanism.What I am doing actually in my API is to save a cookie in the browser to persist
session. Is it possible to request the cookie from my app?
Take a look at an example of using ASWebAuthenticationSession in the documentation here.
Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com