大网数据广告活动
域与目录服务

Why does an MSAL-based iOS app keep asking for credentials with Microsoft Entra?

· 52CE 我爱测

Provides guidance for troubleshooting repeated sign-in prompts in an iOS MSAL implementation

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 ASWebAuthenticationSession instance, and you open external links or logout flows in Safari system browser.
  • Note: ASWebAuthenticationSession is 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 uses WKWebView for related workflows.
  • Note: You can use WKWebView for a consistent experience within your app. However, because it's sandboxed, WKWebView doesn'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.

资料来源与适用范围

资料来源
Microsoft Learn / IT Pro troubleshooting
适用范围
See source applicability · Source date 03/19/2025
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。