-
Notifications
You must be signed in to change notification settings - Fork 360
How to migrate from using iOS Broker on ADAL.NET to MSAL.NET
You've been using ADAL.NET and iOS broker, and it's finally time to migrate to use the next generation Microsoft authentication library, MSAL.NET, which, as of release 4.3, supports the broker on iOS.
Where to start? This document will help you migrate your Xamarin iOS app from ADAL to MSAL.
This document assumes that you already have a Xamarin iOS app that is integrated with the iOS broker. If you do not, it would be best to move directly to MSAL.NET and begin the broker implementation there. See this documentation for details on invoking the iOS broker in MSAL.NET with a new application.
Brokers are applications, provided by Microsoft, on Android and iOS (Microsoft Authenticator on iOS and Android, InTune Company Portal on Android).
They enable:
- Single-Sign-On,
- Device identification, which is required by some conditional access policies (See Device management)
- Application identification verification, also required in some enterprise scenarios (See for instance Intune mobile application management, or MAM)
Current ADAL code: | MSAL counterpart: |
In ADAL.NET, broker support was enabled on a per-authentication context basis, it is disabled by default. You had to set a
public PlatformParameters(
UIViewController callerViewController,
bool useBroker) Also, in the platform specific code, in this example, in the page renderer for iOS, set the
page.BrokerParameters = new PlatformParameters(
this,
true,
PromptBehavior.SelectAccount); Then, include the parameters in the acquire token call: AuthenticationResult result =
await
AuthContext.AcquireTokenAsync(
Resource,
ClientId,
new Uri(RedirectURI),
platformParameters)
.ConfigureAwait(false); |
In MSAL.NET, broker support is enabled on a per-Public Client Application basis. It is disabled by default. You must use the
var app = PublicClientApplicationBuilder
.Create(ClientId)
.WithBroker()
.WithReplyUri(redirectUriOnIos)
.Build(); In the Acquire Token call: result = await app.AcquireTokenInteractive(scopes)
.WithParentActivityOrWindow(App.RootViewController)
.ExecuteAsync(); |
In ADAL.NET, you passed in the UIViewController as part of the PlatformParameters (see example in Step One). However, in MSAL.NET, to give the developer more flexibility, the use of an object window is used, but not required in regular iOS usage. However, in order to use the broker, you will need to set the object window in order to send and receive responses from broker.
Current ADAL code: | MSAL counterpart: |
The UIViewController is passed into the PlatformParamters in the iOS specific platform.
page.BrokerParameters = new PlatformParameters(
this,
true,
PromptBehavior.SelectAccount); |
In MSAL.NET, you will need to do two things to set the object window for iOS:
For example: In public static object RootViewController { get; set; } In LoadApplication(new App());
App.RootViewController = new UIViewController(); In the Acquire Token call: result = await app.AcquireTokenInteractive(scopes)
.WithParentActivityOrWindow(App.RootViewController)
.ExecuteAsync(); |
Both ADAL and MSAL will call the broker, and broker will, in turn, call back to your application through the OpenUrl
method of the AppDelegate
class. More information available here
✔️There are no changes here between ADAL.NET and MSAL.NET
ADAL.NET and MSAL.NET use URLs to invoke the broker and return the broker response back to the app. The URL scheme needs to be registered in the Info.plist
file for your app.
Current ADAL code: | MSAL counterpart: |
The URL Scheme is unique to your app. |
The
as a prefix, followed by your
For example:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>com.yourcompany.xforms</string>
<key>CFBundleURLSchemes</key>
<array>
<string>msauth.com.yourcompany.xforms</string>
</array>
</dict>
</array> Note: This will become part of the RedirectUri used for uniquely identifying the app when receiving the response from broker |
ADAL.NET and MSAL.NET both use
-canOpenURL:
to check if the broker is installed on the device.
Current ADAL code: | MSAL counterpart: |
Uses
<key>LSApplicationQueriesSchemes</key>
<array>
<string>msauth</string>
</array> |
Uses
<key>LSApplicationQueriesSchemes</key>
<array>
<string>msauthv2</string>
</array> |
ADAL.NET and MSAL.NET both add an extra requirement on the redirectUri when targeting broker, and must be registered with your application in the portal.
Current ADAL code: | MSAL counterpart: |
|
example:
|
For more information on registering the redirectUri in the portal, see this page for more details.
- Home
- Why use MSAL.NET
- Is MSAL.NET right for me
- Scenarios
- Register your app with AAD
- Client applications
- Acquiring tokens
- MSAL samples
- Known Issues
- AcquireTokenInteractive
- WAM - the Windows broker
- .NET Core
- Maui Docs
- Custom Browser
- Applying an AAD B2C policy
- Integrated Windows Authentication for domain or AAD joined machines
- Username / Password
- Device Code Flow for devices without a Web browser
- ADFS support
- Acquiring a token for the app
- Acquiring a token on behalf of a user in Web APIs
- Acquiring a token by authorization code in Web Apps
- High Availability
- Token cache serialization
- Logging
- Exceptions in MSAL
- Provide your own Httpclient and proxy
- Extensibility Points
- Clearing the cache
- Client Credentials Multi-Tenant guidance
- Performance perspectives
- Differences between ADAL.NET and MSAL.NET Apps
- PowerShell support
- Testing apps that use MSAL
- Experimental Features
- Proof of Possession (PoP) tokens
- Using in Azure functions
- Extract info from WWW-Authenticate headers
- SPA Authorization Code