|
70 | 70 | import java.util.HashMap; |
71 | 71 | import java.util.Locale; |
72 | 72 | import java.util.Map; |
73 | | -import java.util.Set; |
74 | 73 |
|
75 | 74 | import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker.AMAZON_APP_REDIRECT_PREFIX; |
76 | 75 | import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker.COMPANY_PORTAL_APP_PACKAGE_NAME; |
77 | 76 | import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker.IPPHONE_APP_PACKAGE_NAME; |
78 | 77 | import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker.IPPHONE_APP_SIGNATURE; |
79 | 78 | import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker.PLAY_STORE_INSTALL_PREFIX; |
| 79 | +import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.SWITCH_BROWSER.isSwitchBrowserRequest; |
80 | 80 | import static com.microsoft.identity.common.java.AuthenticationConstants.AAD.APP_LINK_KEY; |
81 | 81 |
|
82 | 82 | import io.opentelemetry.api.trace.SpanContext; |
@@ -312,26 +312,6 @@ private boolean isHeaderForwardingRequiredUri(@NonNull final String url) { |
312 | 312 | return urlIsTrustedToReceiveHeaders && originalRequestHasHeaders; |
313 | 313 | } |
314 | 314 |
|
315 | | - /** |
316 | | - * Check if the request is to switch the browser. |
317 | | - * <p> |
318 | | - * The request is considered "switch_browser" if the URL contains the action URI, code, and action parameters. |
319 | | - * |
320 | | - * @param uri The URI of the request. |
321 | | - * @return True if the request contains the required parameters, false otherwise. |
322 | | - */ |
323 | | - private boolean isSwitchBrowserRequest(@Nullable final Uri uri) { |
324 | | - final Set<String> requiredParams = Set.of( |
325 | | - AuthenticationConstants.SWITCH_BROWSER.ACTION_URI, |
326 | | - AuthenticationConstants.SWITCH_BROWSER.CODE, |
327 | | - AuthenticationConstants.SWITCH_BROWSER.ACTION |
328 | | - ); |
329 | | - if (uri == null) { |
330 | | - return false; |
331 | | - } |
332 | | - return uri.getQueryParameterNames().containsAll(requiredParams); |
333 | | - } |
334 | | - |
335 | 315 | // This function is only called when the client received a redirect that starts with the apps |
336 | 316 | // redirect uri. |
337 | 317 | protected void processRedirectUrl(@NonNull final WebView view, @NonNull final String url) { |
@@ -362,17 +342,11 @@ protected boolean processSwitchToBrowserRequest(@NonNull final Uri uri) { |
362 | 342 | Logger.error(TAG, "Switch browser action URI or code is null. Cannot switch browser.", null); |
363 | 343 | return false; |
364 | 344 | } |
365 | | - final String[] paths = action_uri.split("/"); |
366 | | - final String authority = paths[0]; |
367 | | - final Uri.Builder uriBuilder = new Uri.Builder() |
368 | | - .scheme("https") |
369 | | - .encodedAuthority(authority) |
370 | | - .appendQueryParameter(AuthenticationConstants.SWITCH_BROWSER.CODE, code) |
371 | | - .appendQueryParameter(AuthenticationConstants.OAuth2.REDIRECT_URI, mRedirectUrl); |
372 | | - for (int i = 1; i < paths.length; i++) { |
373 | | - uriBuilder.appendPath(paths[i]); |
374 | | - } |
375 | | - return fragment.launchWebBrowserIntent(uriBuilder.build()); |
| 345 | + final HashMap<String, String> queryParams = new HashMap<>(); |
| 346 | + queryParams.put(AuthenticationConstants.SWITCH_BROWSER.CODE, code); |
| 347 | + queryParams.put(AuthenticationConstants.OAuth2.REDIRECT_URI, mRedirectUrl); |
| 348 | + final Uri swithBrowserUri = fragment.constructSwithBrowserUri(action_uri, queryParams); |
| 349 | + return fragment.launchWebBrowserIntent(swithBrowserUri); |
376 | 350 | } |
377 | 351 |
|
378 | 352 | private void processWebsiteRequest(@NonNull final WebView view, @NonNull final String url) { |
|
0 commit comments