You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/active-directory/develop/msal-android-single-sign-on.md
+41-39Lines changed: 41 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,9 +11,8 @@ ms.workload: identity
11
11
ms.tgt_pltfrm: android
12
12
ms.devlang: java
13
13
ms.topic: how-to
14
-
ms.date: 10/15/2020
14
+
ms.date: 01/18/2023
15
15
ms.author: henrymbugua
16
-
ms.reviewer: marsma
17
16
---
18
17
19
18
# Enable cross-app SSO on Android using MSAL
@@ -28,35 +27,34 @@ In this how-to, you'll learn how to configure the SDKs used by your application
28
27
29
28
This how-to assumes you know how to:
30
29
31
-
- Provision your app using the Azure portal. For more information on this topic, see the instructions for creating an app in [the Android tutorial](./tutorial-v2-android.md#create-a-project)
32
-
- Integrate your application with the [Microsoft Authentication Library for Android](https://github.com/AzureAD/microsoft-authentication-library-for-android).
30
+
- Provision your app using the Azure portal. For more information, see the instructions for creating an app in [the Android tutorial](./tutorial-v2-android.md#create-a-project)
31
+
- Integrate your application with the [MSAL for Android](https://github.com/AzureAD/microsoft-authentication-library-for-android)
33
32
34
-
## Methods for single sign-on
33
+
## Methods for SSO
35
34
36
35
There are two ways for applications using MSAL for Android to achieve SSO:
37
36
38
-
* Through a [broker application](#sso-through-brokered-authentication)
39
-
* Through the [system browser](#sso-through-system-browser)
37
+
- Through a [broker application](#sso-through-brokered-authentication)
38
+
- Through the [system browser](#sso-through-system-browser)
40
39
41
-
42
-
It is recommended to use a broker application for benefits like device-wide SSO, account management, and conditional access. However, it requires your users to download additional applications.
40
+
It's recommended to use a broker application for benefits like device-wide SSO, account management, and conditional access. However, it requires your users to download additional applications.
43
41
44
42
## SSO through brokered authentication
45
43
46
-
We recommend that you use one of Microsoft's authentication brokers to participate in device-wide single sign-on (SSO) and to meet organizational Conditional Access policies. Integrating with a broker provides the following benefits:
44
+
We recommend that you use one of Microsoft's authentication brokers to participate in device-wide SSO and to meet organizational Conditional Access policies. Integrating with a broker provides the following benefits:
47
45
48
-
- Device single sign-on
46
+
- Device SSO
49
47
- Conditional Access for:
50
48
- Intune App Protection
51
49
- Device Registration (Workplace Join)
52
50
- Mobile Device Management
53
51
- Device-wide Account Management
54
-
-via Android AccountManager & Account Settings
52
+
- via Android AccountManager & Account Settings
55
53
- "Work Account" - custom account type
56
54
57
55
On Android, the Microsoft Authentication Broker is a component that's included in the [Microsoft Authenticator](https://play.google.com/store/apps/details?id=com.azure.authenticator) and [Intune Company Portal](https://play.google.com/store/apps/details?id=com.microsoft.windowsintune.companyportal) apps.
58
56
59
-
The following diagram illustrates the relationship between your app, the Microsoft Authentication Library (MSAL), and Microsoft's authentication brokers.
57
+
The following diagram illustrates the relationship between your app, the MSAL, and Microsoft's authentication brokers.
60
58
61
59

62
60
@@ -74,7 +72,7 @@ If a device doesn't already have a broker app installed, MSAL instructs the user
74
72
75
73
#### When a broker is installed
76
74
77
-
When a broker is installed on a device, all subsequent interactive token requests (calls to `acquireToken()`) are handled by the broker rather than locally by MSAL. Any SSO state previously available to MSAL is not available to the broker. As a result, the user will need to authenticate again, or select an account from the existing list of accounts known to the device.
75
+
When a broker is installed on a device, all subsequent interactive token requests (calls to `acquireToken()`) are handled by the broker rather than locally by MSAL. Any SSO state previously available to MSAL isn't available to the broker. As a result, the user will need to authenticate again, or select an account from the existing list of accounts known to the device.
78
76
79
77
Installing a broker doesn't require the user to sign in again. Only when the user needs to resolve an `MsalUiRequiredException` will the next request go to the broker. `MsalUiRequiredException` can be thrown for several reasons, and needs to be resolved interactively. For example:
80
78
@@ -86,9 +84,9 @@ Installing a broker doesn't require the user to sign in again. Only when the use
86
84
87
85
#### When a broker is uninstalled
88
86
89
-
If there is only one broker hosting app installed, and it is removed, then the user will need to sign in again. Uninstalling the active broker removes the account and associated tokens from the device.
87
+
If there's only one broker hosting app installed, and it's removed, then the user will need to sign in again. Uninstalling the active broker removes the account and associated tokens from the device.
90
88
91
-
If Intune Company Portal is installed and is operating as the active broker, and Microsoft Authenticator is also installed, then if the Intune Company Portal (active broker) is uninstalled the user will need to sign in again. Once they sign in again, the Microsoft Authenticator app becomes the active broker.
89
+
If Intune Company Portal is installed and is operating as the active broker, and Microsoft Authenticator is also installed, then if the Intune Company Portal (active broker) is uninstalled the user will need to sign in again. Once they sign in again, the Microsoft Authenticator app becomes the active broker.
Once you've generated a signature hash with *keytool*, use the Azure portal to generate the redirect URI:
113
+
Once you've generated a signature hash with _keytool_, use the Azure portal to generate the redirect URI:
116
114
117
-
1. Sign in to the <ahref="https://portal.azure.com/"target="_blank">Azure portal</a> and select your Android app in **App registrations**.
118
-
1. Select **Authentication** > **Add a platform** > **Android**.
115
+
1. Sign in to the <ahref="https://portal.azure.com/"target="_blank">Azure portal</a>.
116
+
1. If you have access to multiple tenants, use the **Directories + subscriptions** filter :::image type="icon" source="/azure/active-directory/develop/media/common/portal-directory-subscription-filter.png" border="false"::: in the top menu to switch to the tenant in which you registered your application.
117
+
1. Search for and select **Azure Active Directory**.
118
+
1. Under **Manage**, select **App registrations**.
119
+
1. Under **Manage**, select **App registrations**, then select your application.
120
+
1. Under **Manage**, select **Authentication** > **Add a platform** > **Android**.
119
121
1. In the **Configure your Android app** pane that opens, enter the **Signature hash** that you generated earlier and a **Package name**.
120
122
1. Select the **Configure** button.
121
123
@@ -151,29 +153,29 @@ If you get an `MsalClientException` with error code `"BROKER_BIND_FAILURE"`, the
151
153
It might not be immediately clear that broker integration is working, but you can use the following steps to check:
152
154
153
155
1. On your Android device, complete a request using the broker.
154
-
1. In the settings on your Android device, look for a newly created account corresponding to the account that you authenticated with. The account should be of type *Work account*.
156
+
1. In the settings on your Android device, look for a newly created account corresponding to the account that you authenticated with. The account should be of type _Work account_.
155
157
156
158
You can remove the account from settings if you want to repeat the test.
157
159
158
160
## SSO through system browser
159
161
160
-
Android applications have the option to use the WebView, system browser, or Chrome Custom Tabs for authentication user experience. If the application is not using brokered authentication, it will need to use the system browser rather than the native webview in order to achieve SSO.
162
+
Android applications have the option to use the WebView, system browser, or Chrome Custom Tabs for authentication user experience. If the application isn't using brokered authentication, it will need to use the system browser rather than the native webview in order to achieve SSO.
161
163
162
164
### Authorization agents
163
165
164
166
Choosing a specific strategy for authorization agents is optional and represents additional functionality apps can customize. Most apps will use the MSAL defaults (see [Understand the Android MSAL configuration file](msal-configuration.md) to see the various defaults).
165
167
166
-
MSAL supports authorization using a `WebView`, or the system browser. The image below shows how it looks using the `WebView`, or the system browser with CustomTabs or without CustomTabs:
168
+
MSAL supports authorization using a `WebView`, or the system browser. The image below shows how it looks using the `WebView`, or the system browser with CustomTabs or without CustomTabs:
By default, applications integrated with MSAL use the system browser's Custom Tabs to authorize. Unlike WebViews, Custom Tabs share a cookie jar with the default system browser enabling fewer sign-ins with web or other native apps that have integrated with Custom Tabs.
173
175
174
176
If the application uses a `WebView` strategy without integrating Microsoft Authenticator or Company Portal support into their app, users won't have a single sign-on experience across the device or between native apps and web apps.
175
177
176
-
If the application uses MSAL with a broker like Microsoft Authenticator or Intune Company Portal, then users can have a SSO experience across applications if the they have an active sign-in with one of the apps.
178
+
If the application uses MSAL with a broker like Microsoft Authenticator or Intune Company Portal, then users can have SSO experience across applications if they have an active sign-in with one of the apps.
177
179
178
180
### WebView
179
181
@@ -183,7 +185,7 @@ To use the in-app WebView, put the following line in the app configuration JSON
183
185
"authorization_user_agent" : "WEBVIEW"
184
186
```
185
187
186
-
When using the in-app `WebView`, the user signs in directly to the app. The tokens are kept inside the sandbox of the app and aren't available outside the app's cookie jar. As a result, the user can't have a SSO experience across applications unless the apps integrate with the Authenticator or Company Portal.
188
+
When using the in-app `WebView`, the user signs in directly to the app. The tokens are kept inside the sandbox of the app and aren't available outside the app's cookie jar. As a result, the user can't have SSO experience across applications unless the apps integrate with the Authenticator or Company Portal.
187
189
188
190
However, `WebView` does provide the capability to customize the look and feel for sign-in UI. See [Android WebViews](https://developer.android.com/reference/android/webkit/WebView) for more about how to do this customization.
189
191
@@ -195,36 +197,36 @@ By default, MSAL uses the browser and a [custom tabs](https://developer.chrome.c
195
197
"authorization_user_agent" : "BROWSER"
196
198
```
197
199
198
-
Use this approach to provide a SSO experience through the device's browser. MSAL uses a shared cookie jar, which allows other native apps or web apps to achieve SSO on the device by using the persist session cookie set by MSAL.
200
+
Use this approach to provide SSO experience through the device's browser. MSAL uses a shared cookie jar, which allows other native apps or web apps to achieve SSO on the device by using the persist session cookie set by MSAL.
199
201
200
202
### Browser selection heuristic
201
203
202
204
Because it's impossible for MSAL to specify the exact browser package to use on each of the broad array of Android phones, MSAL implements a browser selection heuristic that tries to provide the best cross-device SSO.
203
205
204
206
MSAL primarily retrieves the default browser from the package manager and checks if it is in a tested list of safe browsers. If not, MSAL falls back on using the Webview rather than launching another non-default browser from the safe list. The default browser will be chosen regardless of whether it supports custom tabs. If the browser supports Custom Tabs, MSAL will launch the Custom Tab. Custom Tabs have a look and feel closer to an in-app `WebView` and allow basic UI customization. See [Custom Tabs in Android](https://developer.chrome.com/multidevice/android/customtabs) to learn more.
205
207
206
-
If there are no browser packages on the device, MSAL uses the in-app `WebView`. If the device default setting isn't changed, the same browser should be launched for each signin to ensure a SSO experience.
208
+
If there are no browser packages on the device, MSAL uses the in-app `WebView`. If the device default setting isn't changed, the same browser should be launched for each sign-in to ensure SSO experience.
207
209
208
210
#### Tested Browsers
209
211
210
212
The following browsers have been tested to see if they correctly redirect to the `"redirect_uri"` specified in the configuration file:
<sup>1</sup>Samsung's built-in browser is Samsung Internet.<br/>
225
227
<sup>2</sup>Huawei's built-in browser is Huawei Browser.<br/>
226
228
<sup>3</sup>The default browser can't be changed inside the Oppo device setting.
227
229
228
230
## Next steps
229
231
230
-
[Shared device mode for Android devices](msal-android-shared-devices.md) allows you to configure an Android device so that it can be easily shared by multiple employees.
232
+
[Shared device mode for Android devices](msal-android-shared-devices.md) allows you to configure an Android device so that it can be easily shared by multiple employees.
0 commit comments