Summary
This article provides guidance for troubleshooting repeated sign-in prompts in an iOS app that uses Microsoft Authentication Library (MSAL).
Symptoms
You follow this tutorial to integrate Microsoft identity platform authentication in your iOS app by using the Microsoft Authentication Library (MSAL) SDK. However, after the initial login, users are unexpectedly prompted to sign in multiple times.
Cause
This issue is typically caused by the web browser used by MSAL does not allow cookie sharing.
The tutorial uses the MSAL to implement authentication. MSAL SDK facilitates authentication by automatically renewing tokens. It also enables single sign-on (SSO) between other apps on the device and manages user accounts.
For SSO to function correctly, tokens must be shared between apps. To meet this requirement, you must use a token cache or a broker application, such as Microsoft Authenticator for iOS. Interactive authentication in MSAL requires a web browser. On iOS, MSAL uses the Safari system browser by default for interactive authentication. This default setup supports SSO state sharing between apps.
However, if you customize the browser configuration for authentication, such as by using one of the following options, cookie sharing might not be enabled by default.
| For iOS only | For iOS and macOS |
|---|---|
| SFAuthenticationSession SFSafariViewController | ASWebAuthenticationSession WKWebView |
Resolution
To prevent repeated login prompts, you must allow cookie sharing when you customize the browser. To enable SSO and cookie sharing between MSAL and your iOS app, use one of the following solutions:
Use ASWebAuthenticationSession and Safari system browser (UIApplication.shared.open)
- Use Case: Your app uses MSAL together with the default
ASWebAuthenticationSessioninstance, and you open external links or logout flows in Safari system browser. - Note:
ASWebAuthenticationSessionis the recommended method for MSAL interactive authentication on iOS 12+. It's the only supported method on iOS 13+. This method is privacy-preserving and shares cookies with system browser. SSO works between MSAL and Safari browser application because they share cookies through the system authentication session.
Use WKWebView
- Use Case: You explicitly configure MSAL to use
WKWebView, and your app also usesWKWebViewfor related workflows. - Note: You can use
WKWebViewfor a consistent experience within your app. However, because it's sandboxed,WKWebViewdoesn't share session cookies with Safari system browser or other apps. In this condition, SSO support is limited to use within your app.
For more information, see Customizing webviews and browsers.
Third-party information disclaimer
The third-party products that this article discusses are manufactured by companies that are independent of Microsoft. Microsoft makes no warranty, implied or otherwise, about the performance or reliability of these products.
Source: Microsoft Learn / IT Pro troubleshooting by Microsoft and contributors (upstream author metadata: daga). Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.
