Skip to content

Commit 8b7bb1f

Browse files
authored
Merge pull request #215738 from henrymbuguakiarie/msid-update-tutorial-v2-shared-device-mode
[msid][pm-update] tutorial-v2-shared-device-mode(ADO-2132925)
2 parents d351d43 + f8d9f56 commit 8b7bb1f

File tree

1 file changed

+51
-25
lines changed

1 file changed

+51
-25
lines changed

articles/active-directory/develop/tutorial-v2-shared-device-mode.md

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ms.service: active-directory
99
ms.subservice: develop
1010
ms.topic: tutorial
1111
ms.workload: identity
12-
ms.date: 1/15/2020
12+
ms.date: 11/03/2022
1313
ms.author: henrymbugua
1414
ms.reviewer: brandwe
1515
ms.custom: aaddev, identityplatformtop40
@@ -22,13 +22,14 @@ In this tutorial, Android developers and Azure Active Directory (Azure AD) tenan
2222
In this tutorial:
2323

2424
> [!div class="checklist"]
25-
> * Download a code sample
26-
> * Enable and detect shared-device mode
27-
> * Detect single or multiple account mode
28-
> * Detect a user switch, and enable global sign-in and sign-out
29-
> * Set up tenant and register the application in the Azure portal
30-
> * Set up an Android device in shared-device mode
31-
> * Run the sample app
25+
>
26+
> - Download a code sample
27+
> - Enable and detect shared-device mode
28+
> - Detect single or multiple account mode
29+
> - Detect a user switch, and enable global sign-in and sign-out
30+
> - Set up tenant and register the application in the Azure portal
31+
> - Set up an Android device in shared-device mode
32+
> - Run the sample app
3233
3334
## Prerequisites
3435

@@ -64,21 +65,21 @@ Here's an example of the auth_config.json file included in the **app**>**main**>
6465

6566
```json
6667
{
67-
"client_id":"Client ID after app registration at https://aka.ms/MobileAppReg",
68-
"authorization_user_agent":"DEFAULT",
69-
"redirect_uri":"Redirect URI after app registration at https://aka.ms/MobileAppReg",
70-
"account_mode":"SINGLE",
71-
"broker_redirect_uri_registered": true,
72-
"shared_device_mode_supported": true,
73-
"authorities":[
74-
{
75-
"type":"AAD",
76-
"audience":{
77-
"type": "AzureADandPersonalMicrosoftAccount",
78-
"tenant_id":"common"
79-
}
80-
}
81-
]
68+
"client_id": "Client ID after app registration at https://aka.ms/MobileAppReg",
69+
"authorization_user_agent": "DEFAULT",
70+
"redirect_uri": "Redirect URI after app registration at https://aka.ms/MobileAppReg",
71+
"account_mode": "SINGLE",
72+
"broker_redirect_uri_registered": true,
73+
"shared_device_mode_supported": true,
74+
"authorities": [
75+
{
76+
"type": "AAD",
77+
"audience": {
78+
"type": "AzureADandPersonalMicrosoftAccount",
79+
"tenant_id": "common"
80+
}
81+
}
82+
]
8283
}
8384
```
8485

@@ -88,7 +89,7 @@ Shared-device mode allows you to configure Android devices to be shared by multi
8889

8990
Use `isSharedDevice()` to determine if an app is running on a device that is in shared-device mode. Your app could use this flag to determine if it should modify UX accordingly.
9091

91-
Here's a code snippet that shows how you could use `isSharedDevice()`. It's from the `SingleAccountModeFragment` class in the sample app:
92+
Here's a code snippet that shows how you could use `isSharedDevice()`. It's from the `SingleAccountModeFragment` class in the sample app:
9293

9394
```Java
9495
deviceModeTextView.setText(mSingleAccountApp.isSharedDevice() ? "Shared" : "Non-Shared");
@@ -204,6 +205,31 @@ private void onSignOutClicked()
204205
}
205206
```
206207

208+
### Receive broadcast to detect global sign out initiated from other applications
209+
210+
To receive the account change broadcast, you'll need to register a broadcast receiver.  It’s recommended to register your broadcast receiver via the [Context-registered receivers](https://developer.android.com/guide/components/broadcasts#context-registered-receivers).
211+
212+
When an account change broadcast is received, immediately [get the signed in user and determine if a user has changed on the device](#get-the-signed-in-user-and-determine-if-a-user-has-changed-on-the-device). If a change is detected, initiate data cleanup for previously signed-in account. It is recommended to properly stop any operations and do data cleanup.
213+
214+
The following code snippet shows how you could register a broadcast receiver.
215+
216+
```java
217+
private static final String CURRENT_ACCOUNT_CHANGED_BROADCAST_IDENTIFIER = "com.microsoft.identity.client.sharedmode.CURRENT_ACCOUNT_CHANGED";
218+
private BroadcastReceiver mAccountChangedBroadcastReceiver;
219+
private void registerAccountChangeBroadcastReceiver(){
220+
    mAccountChangedBroadcastReceiver = new BroadcastReceiver() {
221+
        @Override
222+
        public void onReceive(Context context, Intent intent) {
223+
            //INVOKE YOUR PRIOR ACCOUNT CLEAN UP LOGIC HERE      
224+
        }
225+
    };
226+
    IntentFilter filter = new
227+
228+
IntentFilter(CURRENT_ACCOUNT_CHANGED_BROADCAST_IDENTIFIER);
229+
    this.registerReceiver(mAccountChangedBroadcastReceiver, filter);
230+
}
231+
```
232+
207233
## Administrator guide
208234
209235
The following steps describe setting up your application in the Azure portal and putting your device into shared-device mode.
@@ -257,7 +283,7 @@ The device is now in shared mode.
257283

258284
:::image type="content" source="media/tutorial-v2-shared-device-mode/shared-device-mode-screen.png" alt-text="App screen showing shared device mode enabled":::
259285

260-
Any sign-ins and sign-outs on the device will be global, meaning they apply to all apps that are integrated with MSAL and Microsoft Authenticator on the device. You can now deploy applications to the device that use shared-device mode features.
286+
Any sign-ins and sign-outs on the device will be global, meaning they apply to all apps that are integrated with MSAL and Microsoft Authenticator on the device. You can now deploy applications to the device that use shared-device mode features.
261287

262288
## View the shared device in the Azure portal
263289

0 commit comments

Comments
 (0)