Skip to content

Commit 58c771c

Browse files
committed
used defined browsers for duna flow
1 parent 9385aba commit 58c771c

File tree

24 files changed

+211
-153
lines changed

24 files changed

+211
-153
lines changed

common/src/main/java/com/microsoft/identity/common/adal/internal/AuthenticationConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ public static final class AAD {
534534
}
535535

536536
/**
537-
* Represents the constants value for the DUNA flow.
537+
* Represents the constants value for the SwitchBrowser protocol.
538538
*/
539539
@NoArgsConstructor(access = AccessLevel.PRIVATE)
540540
public static final class SWITCH_BROWSER {

common/src/main/java/com/microsoft/identity/common/components/AndroidPlatformComponentsFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.microsoft.identity.common.internal.platform.AndroidPlatformUtil;
3636
import com.microsoft.identity.common.internal.providers.oauth2.AndroidTaskStateGenerator;
3737
import com.microsoft.identity.common.internal.ui.AndroidAuthorizationStrategyFactory;
38+
import com.microsoft.identity.common.internal.ui.browser.BrowserSelector;
3839
import com.microsoft.identity.common.java.WarningType;
3940
import com.microsoft.identity.common.java.interfaces.IPlatformComponents;
4041
import com.microsoft.identity.common.java.interfaces.PlatformComponents;
@@ -127,7 +128,8 @@ public static void fillBuilderWithBasicImplementations(
127128
.storageSupplier(new AndroidStorageSupplier(context,
128129
new AndroidAuthSdkStorageEncryptionManager(context)))
129130
.platformUtil(new AndroidPlatformUtil(context, activity))
130-
.httpClientWrapper(new DefaultHttpClientWrapper());
131+
.httpClientWrapper(new DefaultHttpClientWrapper())
132+
.browserSelector(new BrowserSelector(context));
131133

132134
if (activity != null){
133135
builder.authorizationStrategyFactory(

common/src/main/java/com/microsoft/identity/common/internal/broker/BrokerRequest.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import com.microsoft.identity.common.java.ui.PreferredAuthMethod;
3535

3636
import java.io.Serializable;
37-
import java.util.List;
3837

3938
import lombok.Builder;
4039
import lombok.Getter;
@@ -80,7 +79,6 @@ private static final class SerializedNames {
8079
final static String PREFERRED_AUTH_METHOD = "preferred_auth_method";
8180
final static String ACCOUNT_TRANSFER_TOKEN = "account_transfer_token";
8281
final static String SUPPRESS_ACCOUNT_PICKER = "suppress_account_picker";
83-
final static String BROWSER_SAFE_LIST = "browser_safe_list";
8482
}
8583

8684
/**
@@ -187,6 +185,7 @@ private static final class SerializedNames {
187185
/**
188186
* Boolean if set, will try to refresh the token instead of using it from cache.
189187
*/
188+
@Nullable
190189
@SerializedName(SerializedNames.FORCE_REFRESH)
191190
private boolean mForceRefresh;
192191

@@ -228,6 +227,7 @@ private static final class SerializedNames {
228227
/**
229228
* Boolean indicated whether app supports multiple clouds.
230229
*/
230+
@NonNull
231231
@SerializedName(SerializedNames.MULTIPLE_CLOUDS_SUPPORTED)
232232
private boolean mMultipleCloudsSupported;
233233

@@ -239,6 +239,7 @@ private static final class SerializedNames {
239239
@SerializedName(SerializedNames.AUTHENTICATION_SCHEME)
240240
private AbstractAuthenticationScheme mAuthenticationScheme;
241241

242+
@Nullable
242243
@SerializedName(SerializedNames.POWER_OPT_CHECK_ENABLED)
243244
private boolean mPowerOptCheckEnabled;
244245

@@ -265,10 +266,4 @@ private static final class SerializedNames {
265266
*/
266267
@SerializedName(SerializedNames.SUPPRESS_ACCOUNT_PICKER)
267268
private boolean mSuppressAccountPicker;
268-
269-
/**
270-
* List of browsers that are safe to use for the request.
271-
*/
272-
@SerializedName(SerializedNames.BROWSER_SAFE_LIST)
273-
private List<BrowserDescriptor> mBrowserSafeList;
274269
}

common/src/main/java/com/microsoft/identity/common/internal/controllers/LocalMSALController.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
// THE SOFTWARE.
2323
package com.microsoft.identity.common.internal.controllers;
2424

25+
import android.content.pm.PackageManager;
2526
import android.text.TextUtils;
2627

2728
import androidx.annotation.NonNull;
@@ -31,10 +32,12 @@
3132
import com.microsoft.identity.common.internal.telemetry.Telemetry;
3233
import com.microsoft.identity.common.internal.telemetry.events.ApiEndEvent;
3334
import com.microsoft.identity.common.internal.telemetry.events.ApiStartEvent;
35+
import com.microsoft.identity.common.internal.ui.browser.BrowserSelector;
3436
import com.microsoft.identity.common.java.WarningType;
3537
import com.microsoft.identity.common.java.authorities.Authority;
3638
import com.microsoft.identity.common.java.authscheme.AbstractAuthenticationScheme;
3739
import com.microsoft.identity.common.java.authscheme.IPoPAuthenticationSchemeParams;
40+
import com.microsoft.identity.common.java.browser.Browser;
3841
import com.microsoft.identity.common.java.cache.ICacheRecord;
3942
import com.microsoft.identity.common.java.commands.parameters.CommandParameters;
4043
import com.microsoft.identity.common.java.commands.parameters.DeviceCodeFlowCommandParameters;
@@ -226,7 +229,13 @@ private AuthorizationResult performAuthorizationRequest(@NonNull final OAuth2Str
226229
.getPlatformUtil()
227230
.throwIfNetworkNotAvailable(parameters.isPowerOptCheckEnabled());
228231

229-
mAuthorizationStrategy = parameters.getPlatformComponents().getAuthorizationStrategyFactory().getAuthorizationStrategy(parameters);
232+
final Browser browser = parameters.getPlatformComponents().getBrowserSelector().select(
233+
parameters.getBrowserSafeList(),
234+
parameters.getPreferredBrowser()
235+
);
236+
mAuthorizationStrategy = parameters.getPlatformComponents()
237+
.getAuthorizationStrategyFactory()
238+
.getAuthorizationStrategy(parameters.getAuthorizationAgent(),browser, false);
230239
mAuthorizationRequest = getAuthorizationRequest(strategy, parameters);
231240

232241
// Suppressing unchecked warnings due to casting of AuthorizationRequest to GenericAuthorizationRequest and AuthorizationStrategy to GenericAuthorizationStrategy in the arguments of call to requestAuthorization method

common/src/main/java/com/microsoft/identity/common/internal/platform/AndroidPlatformUtil.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import java.security.NoSuchAlgorithmException;
6161
import java.util.AbstractMap;
6262
import java.util.ArrayList;
63+
import java.util.Collections;
6364
import java.util.HashSet;
6465
import java.util.List;
6566
import java.util.Map;
@@ -102,6 +103,36 @@ public List<BrowserDescriptor> getBrowserSafeListForBroker() {
102103
return browserDescriptors;
103104
}
104105

106+
/**
107+
* Return a list of BrowserDescriptors that are considered safe for the Switch to browser flow.
108+
*/
109+
@Override
110+
public List<BrowserDescriptor> getBrowserSafeListForSwitchBrowser() {
111+
List<BrowserDescriptor> browserDescriptors = new ArrayList<>();
112+
// Chrome
113+
final HashSet<String> chromeSignatureHashes = new HashSet<>();
114+
chromeSignatureHashes.add("7fmduHKTdHHrlMvldlEqAIlSfii1tl35bxj1OXN5Ve8c4lU6URVu4xtSHc3BVZxS6WWJnxMDhIfQN0N0K2NDJg==");
115+
final BrowserDescriptor chrome = new BrowserDescriptor(
116+
"com.android.chrome",
117+
chromeSignatureHashes,
118+
null,
119+
null
120+
);
121+
// Edge
122+
final HashSet<String> edgeSignatureHashes = new HashSet<>();
123+
chromeSignatureHashes.add("Ivy-Rk6ztai_IudfbyUrSHugzRqAtHWslFvHT0PTvLMsEKLUIgv7ZZbVxygWy_M5mOPpfjZrd3vOx3t-cA6fVQ==");
124+
final BrowserDescriptor edge = new BrowserDescriptor(
125+
"com.microsoft.emmx",
126+
chromeSignatureHashes,
127+
null,
128+
null
129+
);
130+
// Add browsers
131+
browserDescriptors.add(chrome);
132+
browserDescriptors.add(edge);
133+
return browserDescriptors;
134+
}
135+
105136
@Nullable
106137
@Override
107138
public String getInstalledCompanyPortalVersion() {

common/src/main/java/com/microsoft/identity/common/internal/providers/oauth2/AuthorizationActivityFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public static Intent getAuthorizationActivityIntent(final Context context,
112112
if (ProcessUtil.isBrokerProcess(context)) {
113113
intent = new Intent(context, BrokerAuthorizationActivity.class);
114114
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
115-
// In the case of a DUNA flow, we need to transition from the browser to the WebView.
115+
// In the case of a SwitchBrowser protocol, we need to transition from the browser to the WebView.
116116
// These flags ensure that we have a new task stack that allows for this transition.
117117
} else if (libraryConfig.isAuthorizationInCurrentTask() && !authorizationAgent.equals(AuthorizationAgent.WEBVIEW)) {
118118
// We exclude the case when the authorization agent is already selected as WEBVIEW because of confusion

common/src/main/java/com/microsoft/identity/common/internal/providers/oauth2/WebViewAuthorizationFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ public ActivityResultLauncher<LegacyFido2ApiObject> getFidoLauncher() {
468468
public boolean launchWebBrowserIntent(@NonNull final Uri uri) {
469469
final String methodTag = TAG + ":launchWebBrowserIntent";
470470
if (mAuthIntent != null) {
471-
Logger.info(methodTag, "Launching web browser intent for DUNA flow.");
471+
Logger.info(methodTag, "Launching web browser intent for SwitchBrowserProtocol.");
472472
mAuthIntent.setData(uri);
473473
startActivity(mAuthIntent);
474474
return true;

common/src/main/java/com/microsoft/identity/common/internal/request/MsalBrokerRequestAdapter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ public BrokerRequest brokerRequestFromAcquireTokenParameters(@NonNull final Inte
132132
.preferredAuthMethod(parameters.getPreferredAuthMethod())
133133
.accountTransferToken(parameters.getAccountTransferToken())
134134
.suppressAccountPicker(parameters.isSuppressBrokerAccountPicker())
135-
.browserSafeList(parameters.getBrowserSafeList())
136135
.build();
137136

138137
return brokerRequest;

common/src/main/java/com/microsoft/identity/common/internal/ui/AndroidAuthorizationStrategyFactory.java

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,11 @@
2929
import androidx.annotation.Nullable;
3030
import androidx.fragment.app.Fragment;
3131

32-
import com.microsoft.identity.common.internal.ui.browser.Browser;
32+
import com.microsoft.identity.common.java.browser.Browser;
3333
import com.microsoft.identity.common.internal.ui.browser.DefaultBrowserAuthorizationStrategy;
3434
import com.microsoft.identity.common.java.WarningType;
35-
import com.microsoft.identity.common.java.exception.ErrorStrings;
36-
import com.microsoft.identity.common.java.commands.parameters.BrokerInteractiveTokenCommandParameters;
37-
import com.microsoft.identity.common.java.commands.parameters.InteractiveTokenCommandParameters;
3835
import com.microsoft.identity.common.java.configuration.LibraryConfiguration;
3936
import com.microsoft.identity.common.java.providers.oauth2.IAuthorizationStrategy;
40-
import com.microsoft.identity.common.internal.ui.browser.BrowserSelector;
4137
import com.microsoft.identity.common.internal.ui.webview.EmbeddedWebViewAuthorizationStrategy;
4238
import com.microsoft.identity.common.java.ui.AuthorizationAgent;
4339
import com.microsoft.identity.common.logging.Logger;
@@ -51,7 +47,7 @@
5147
@SuppressWarnings(WarningType.rawtype_warning)
5248
@Builder
5349
@Accessors(prefix = "m")
54-
public class AndroidAuthorizationStrategyFactory implements IAuthorizationStrategyFactory{
50+
public class AndroidAuthorizationStrategyFactory implements IAuthorizationStrategyFactory<IAuthorizationStrategy>{
5551
private static final String TAG = AndroidAuthorizationStrategyFactory.class.getSimpleName();
5652

5753
private final Context mContext;
@@ -61,36 +57,28 @@ public class AndroidAuthorizationStrategyFactory implements IAuthorizationStrate
6157
/**
6258
* Get the authorization strategy.
6359
*
64-
* @param parameters The parameters for the command.
60+
* @param authorizationAgent The authorization agent provided by the caller.
61+
* @param browser The browser to use for authorization.
62+
* @param isBrowserRequest True if the request is from browser.
63+
*
6564
* @return The authorization strategy.
6665
*/
6766
@Override
67+
@NonNull
6868
public IAuthorizationStrategy getAuthorizationStrategy(
69-
@NonNull final InteractiveTokenCommandParameters parameters) {
69+
@NonNull final AuthorizationAgent authorizationAgent,
70+
@Nullable final Browser browser,
71+
final boolean isBrowserRequest) {
7072
final String methodTag = TAG + ":getAuthorizationStrategy";
7173

72-
Browser browser;
73-
try {
74-
browser = BrowserSelector.select(
75-
mContext,
76-
parameters.getBrowserSafeList(),
77-
parameters.getPreferredBrowser());
78-
} catch (final Throwable throwable) {
79-
Logger.warn(methodTag, ErrorStrings.NO_AVAILABLE_BROWSER_FOUND);
80-
browser = null;
81-
}
82-
8374
// Use embedded webView if no browser available or authorization agent is webView
84-
if (parameters.getAuthorizationAgent() == AuthorizationAgent.WEBVIEW || browser == null) {
75+
if (authorizationAgent== AuthorizationAgent.WEBVIEW || browser == null) {
8576
Logger.info(methodTag, "Use webView for authorization.");
8677
return getGenericAuthorizationStrategy(browser);
8778
}
8879

8980
Logger.info(methodTag, "Use browser for authorization.");
90-
return getBrowserAuthorizationStrategy(
91-
browser,
92-
(parameters instanceof BrokerInteractiveTokenCommandParameters));
93-
81+
return getBrowserAuthorizationStrategy(browser, isBrowserRequest);
9482
}
9583

9684
/**

common/src/main/java/com/microsoft/identity/common/internal/ui/CurrentTaskBrowserAuthorizationStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import androidx.annotation.Nullable;
3131
import androidx.fragment.app.Fragment;
3232

33-
import com.microsoft.identity.common.internal.ui.browser.Browser;
33+
import com.microsoft.identity.common.java.browser.Browser;
3434
import com.microsoft.identity.common.internal.ui.browser.BrowserAuthorizationStrategy;
3535
import com.microsoft.identity.common.java.WarningType;
3636
import com.microsoft.identity.common.java.providers.oauth2.AuthorizationRequest;

0 commit comments

Comments
 (0)