Share session from ASWebAuthenticationSession with WKWebView

Hello everyone,

In my application, i have implemented authentication using ASWebauthenticationSession. However, when redirecting the user to a WKWebView, no cookies are shared, causing the session to be lost and requiring the user to log in again.

Is there a way to share cookies between the two? If not, what would be the best approach to set up authentication that ensures SSO when switching to a WebView ?

Thank you very much for your help !

ASWebAuthenticationSession is a full web browser instance, with access to web browser features and the web browser's cookies. WKWebView on the other hand is a way to embed web content inside another app.

Conceptually, ASWebAuthenticationSession is managed by Safari, and WKWebView is managed by your app. There's no way to share cookies between the two.

  • If you control the service you're signing in to, you could set up Associated Domains for your app and use WKWebView entirely. Using Associated Domains would mean you get the best AutoFill experience in your WKWebView, and have access to features like passkeys.
  • If not, your options are more limited. If the service supports it, you may be able to use the auth token you receive from ASWebAuthenticationSession to bootstrap the session in the WKWebView, but depending on the service that may or may not be a viable option.
Share session from ASWebAuthenticationSession with WKWebView
 
 
Q