Skip to content

Commit b7c6243

Browse files
authored
Fix for App Link Usage in DUNA / SSO scenarios (#2363)
See related common PR: AzureAD/microsoft-authentication-library-common-for-android#2745
1 parent ed72371 commit b7c6243

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ MSAL Wiki : https://github.com/AzureAD/microsoft-authentication-library-for-andr
33
vNext
44
----------
55
- [PATCH] Add null checks for guest account ids (#2361)
6+
- [MINOR] Fix for App Link Usage in DUNA / SSO scenarios (#2363)
67

78
Version 7.0.3
89
----------

common

Submodule common updated 33 files

gradle/versions.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ext {
2525
androidxCoreVersion = "1.5.0"
2626
annotationVersion = "1.0.0"
2727
appCompatVersion = "1.1.0"
28-
browserVersion = "1.0.0"
28+
browserVersion = "1.7.0"
2929
constraintLayoutVersion = "1.1.3"
3030
dexmakerMockitoVersion = "2.19.0"
3131
espressoCoreVersion = "3.1.0"

msal/src/main/java/com/microsoft/identity/client/CurrentTaskBrowserTabActivity.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
// THE SOFTWARE.
2323
package com.microsoft.identity.client;
2424

25+
import android.annotation.SuppressLint;
2526
import android.app.Activity;
2627
import android.content.BroadcastReceiver;
2728
import android.content.ComponentName;
@@ -34,8 +35,6 @@
3435
import android.os.Bundle;
3536
import android.widget.Toast;
3637

37-
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
38-
3938
import com.microsoft.identity.common.internal.providers.oauth2.CurrentTaskBrowserAuthorizationFragment;
4039
import com.microsoft.identity.common.internal.util.StringUtil;
4140
import com.microsoft.identity.common.logging.Logger;
@@ -58,7 +57,7 @@
5857
* <intent-filter>
5958
* <action android:name="android.intent.action.VIEW" />
6059
*
61-
* To receive implicit intents, have to put the activity in the category of default.
60+
* To receive implicit intents, have to put the category of default.
6261
* <category android:name="android.intent.category.DEFAULT" />
6362
*
6463
* The target activity allows itself to be started by a web browser to display data.
@@ -73,7 +72,6 @@ public final class CurrentTaskBrowserTabActivity extends Activity {
7372
private static final String TAG = CurrentTaskBrowserTabActivity.class.getSimpleName();
7473
private static final int REDIRECT_RECEIVED_CODE = 2;
7574
private BroadcastReceiver mCloseBroadcastReceiver;
76-
//private int mTaskIdResponseFor;
7775

7876

7977
@Override
@@ -98,17 +96,18 @@ && getIntent() != null
9896
}
9997
}
10098

99+
@SuppressLint("UnspecifiedRegisterReceiverFlag")
101100
@Override
102101
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
103102
super.onActivityResult(requestCode, resultCode, data);
104103

105104
final String methodTag = TAG + ":onActivityResult";
106105

107106
if (resultCode == RESULT_CANCELED) {
108-
// We weren't able to open CurrentTaskAuthorizationActivity from the back stack. Send a broadcast
109-
// instead.
107+
// Send broadcast to notify authorization activity
110108
Intent broadcast = new Intent(REDIRECT_RETURNED_ACTION);
111-
LocalBroadcastManager.getInstance(this).sendBroadcast(broadcast);
109+
broadcast.setPackage(getPackageName()); // Restrict to our app only
110+
sendBroadcast(broadcast);
112111

113112
// Wait for the custom tab to be removed from the back stack before finishing.
114113
mCloseBroadcastReceiver = new BroadcastReceiver() {
@@ -135,16 +134,28 @@ public void onReceive(Context context, Intent intent) {
135134
}
136135
}
137136
};
138-
LocalBroadcastManager.getInstance(this).registerReceiver(
139-
mCloseBroadcastReceiver,
140-
new IntentFilter(DESTROY_REDIRECT_RECEIVING_ACTIVITY_ACTION)
141-
);
137+
138+
IntentFilter filter = new IntentFilter(DESTROY_REDIRECT_RECEIVING_ACTIVITY_ACTION);
139+
// Use backward-compatible receiver registration
140+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
141+
// Use RECEIVER_NOT_EXPORTED for Android 13+ to prevent external apps from sending broadcasts
142+
registerReceiver(mCloseBroadcastReceiver, filter, Context.RECEIVER_NOT_EXPORTED); // 0x4 = RECEIVER_NOT_EXPORTED
143+
} else {
144+
registerReceiver(mCloseBroadcastReceiver, filter);
145+
}
142146
}
143147
}
144148

145149
@Override
146150
protected void onDestroy() {
147-
LocalBroadcastManager.getInstance(this).unregisterReceiver(mCloseBroadcastReceiver);
151+
final String methodTag = TAG + ":onDestroy";
152+
if (mCloseBroadcastReceiver != null) {
153+
try {
154+
unregisterReceiver(mCloseBroadcastReceiver);
155+
} catch (final Exception e) {
156+
Logger.error(methodTag, "Failed to unregister receiver: " + e.getMessage(), e);
157+
}
158+
}
148159
super.onDestroy();
149160
}
150161

0 commit comments

Comments
 (0)