microsoft-authentication-library-for-dotnet
microsoft-authentication-library-for-dotnet copied to clipboard
[Bug] MsalServiceException.ErrorCode is returning "-50005" instead of MsalError.AuthenticationCanceledError when user cancels authentication via a broker on iOS
Library version used
4.59.0
.NET version
net8.0 MAUI 8.0.7 iOS 17.3.1
Scenario
PublicClient - mobile app
Is this a new or an existing app?
This is a new app or experiment
Issue description and reproduction steps
Build a PublicClientApplication using WithBroker On an iOS device install the Authenticator app as a broker Start the authentication flow via AcquireTokenInteractive The Authenticator app opens Click on Cancel in Authenticator An MsalServiceException is thrown with an ErrorCode of "-50005" (defined as iOSBrokerUserCancellationErrorCode inside the inaccessible BrokerResponseConst static class)
Relevant code snippets
var builder = PublicClientApplicationBuilder.Create(MsalClientID)
.WithBroker()
.WithIosKeychainSecurityGroup(MsalKeychainSecurityGroup)
.WithRedirectUri(MsalBrokerRedirectUriOniOS);
var pca = builder.Build();
var authResult = await pca.AcquireTokenInteractive(MsalScopes)
.WithParentActivityOrWindow(App.ParentWindow)
.WithUseEmbeddedWebView(true)
.ExecuteAsync();
Expected behavior
An MsalServiceException with an ErrorCode of MsalError.AuthenticationCanceledError is thrown
Identity provider
Microsoft Entra ID (Work and School accounts and Personal Microsoft accounts)
Regression
No response
Solution and workarounds
No response
Hi @d-philipson, Are you able to provide verbose logs? https://learn.microsoft.com/en-us/entra/msal/dotnet/advanced/exceptions/msal-logging
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:53Z] [GetAccounts] Found 0 RTs and 2 accounts in MSAL cache.
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:53Z] [Instance Discovery] Tried to use network cache provider for login.microsoftonline.com. Success? False.
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:53Z] [Instance Discovery] Tried to use known metadata provider for login.microsoftonline.com. Success? True.
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:53Z] [GetAccounts] Found 0 RTs and 2 accounts in MSAL cache after environment filtering.
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:53Z] [Instance Discovery] Tried to use network cache provider for login.microsoftonline.com. Success? False.
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:53Z] Starting [Oauth2Client] Sending GET request
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:53Z] Starting [HttpManager] ExecuteAsync
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:53Z] [HttpManager] Sending request. Method: GET. Host: https://login.microsoftonline.com.
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:53Z] [HttpManager] Received response. Status code: OK.
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:53Z] Finished [HttpManager] ExecuteAsync in 76 ms
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:53Z] Finished [Oauth2Client] Sending GET request in 80 ms
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:53Z] Starting [OAuth2Client] Deserializing response
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:53Z] Finished [OAuth2Client] Deserializing response in 54 ms
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:53Z] [Instance Discovery] Tried to use network cache provider for login.microsoftonline.com. Success? True.
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:53Z] [Instance Discovery] After hitting the discovery endpoint, the network provider found an entry for login.microsoftonline.com ? True.
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:53Z] Starting iOSBroker:IsBrokerInstalledAndInvokable
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:53Z] Finished iOSBroker:IsBrokerInstalledAndInvokable in 3 ms
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:53Z] Valid MSAL style redirect Uri detected.
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:53Z] Starting iOSBroker:AcquireTokenInteractiveAsync
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:53Z] iOS Broker Payload Count: 15
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:53Z] Starting waiting for broker response
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:58Z] Finished waiting for broker response in 4419 ms
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:58Z] Starting iOSBroker:ProcessBrokerResponse
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:58Z] Processed iOS Broker response. Response Dictionary count: 3
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:58Z] Finished iOSBroker:ProcessBrokerResponse in 58 ms
[0:] MSAL: EventLogLevel: Verbose, Message: False MSAL 4.59.0.0 MSAL.Xamarin.iOS .NET 8.0.0 17.3.1 [2024-03-12 11:56:58Z] Finished iOSBroker:AcquireTokenInteractiveAsync in 4504 ms
[0:] MSAL: EventLogLevel: Error, Message: Broker response returned error: Authentication error - User cancelled authentication flow, ErrorCode: -50005