Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ vNext
- [PATCH] Fix for app link redirect from CCT due to forced browser preference (#2775)
- [MINOR] getAllSsoTokens method for Edge (#2774)
- [MINOR] WebApps AccountId Registry (#2787)
- [MINOR] Take flight value for whether to show webcp flow in weview or not in brokerless scenarios. (#2784)

Version 22.1.3
----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2054,6 +2054,8 @@ public static final class AuthorizationIntentKey {

public static final String WEB_VIEW_ZOOM_ENABLED = "com.microsoft.identity.web.view.zoom.enabled";

public static final String WEB_VIEW_WEB_CP_ENABLED = "com.microsoft.identity.web.view.web.cp.enabled";

public static final String OTEL_CONTEXT_CARRIER = "otel_context_carrier";

public static final String WEB_VIEW_SILENT_AUTHORIZATION_FLOW_TIMEOUT = "com.microsoft.identity.web.view.silent.authorization.flow.timeout";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ object AuthorizationActivityFactory {
AuthenticationConstants.AuthorizationIntentKey.WEB_VIEW_ZOOM_ENABLED,
parameters.webViewZoomEnabled
)
putExtra(
AuthenticationConstants.AuthorizationIntentKey.WEB_VIEW_WEB_CP_ENABLED,
parameters.isWebViewWebCpEnabled
)
putExtra(
DiagnosticContext.CORRELATION_ID,
DiagnosticContext.INSTANCE.requestContext[DiagnosticContext.CORRELATION_ID]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import com.microsoft.identity.common.java.ui.AuthorizationAgent
* @param sourceLibraryVersion Product version to be of library making the request
* @param utid The tenant unique id, if applicable
* @param webViewEnableSilentAuthorizationFlowTimeOutMs If set to a non-null value, this indicates that the flow is silent and specifies the timeout for the silent authorization flow in milliseconds.
* @param isWebViewWebCpEnabled This parameter controls whether webcp URLs should be handled within the WebView or redirected to external browser
*/
data class AuthorizationActivityParameters @JvmOverloads constructor(
val context: Context,
Expand All @@ -57,5 +58,6 @@ data class AuthorizationActivityParameters @JvmOverloads constructor(
* The tenant unique id
*/
val utid: String? = null,
val webViewEnableSilentAuthorizationFlowTimeOutMs: Long? = null
val webViewEnableSilentAuthorizationFlowTimeOutMs: Long? = null,
val isWebViewWebCpEnabled: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.AuthorizationIntentKey.REQUEST_URL;
import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.AuthorizationIntentKey.WEB_VIEW_ZOOM_CONTROLS_ENABLED;
import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.AuthorizationIntentKey.WEB_VIEW_ZOOM_ENABLED;
import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.AuthorizationIntentKey.WEB_VIEW_WEB_CP_ENABLED;
import static com.microsoft.identity.common.java.AuthenticationConstants.SdkPlatformFields.PRODUCT;
import static com.microsoft.identity.common.java.AuthenticationConstants.SdkPlatformFields.VERSION;

Expand Down Expand Up @@ -117,6 +118,8 @@ public class WebViewAuthorizationFragment extends AuthorizationFragment {

private boolean webViewZoomEnabled;

private boolean isWebViewWebcpEnabledInBrokerlessCase;

private String mUtid;

private final CameraPermissionRequestHandler mCameraPermissionRequestHandler = new CameraPermissionRequestHandler(this);
Expand Down Expand Up @@ -201,6 +204,7 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
outState.putSerializable(POST_PAGE_LOADED_URL, mPostPageLoadedJavascript);
outState.putBoolean(WEB_VIEW_ZOOM_CONTROLS_ENABLED, webViewZoomControlsEnabled);
outState.putBoolean(WEB_VIEW_ZOOM_ENABLED, webViewZoomEnabled);
outState.putBoolean(WEB_VIEW_WEB_CP_ENABLED, isWebViewWebcpEnabledInBrokerlessCase);
outState.putString(UTID, mUtid);
}

Expand All @@ -219,6 +223,7 @@ void extractState(@NonNull final Bundle state) {
mPostPageLoadedJavascript = state.getString(POST_PAGE_LOADED_URL);
webViewZoomEnabled = state.getBoolean(WEB_VIEW_ZOOM_ENABLED, true);
webViewZoomControlsEnabled = state.getBoolean(WEB_VIEW_ZOOM_CONTROLS_ENABLED, true);
isWebViewWebcpEnabledInBrokerlessCase = state.getBoolean(WEB_VIEW_WEB_CP_ENABLED, false);
mUtid = state.getString(UTID);
}

Expand Down Expand Up @@ -258,7 +263,8 @@ public void onPageLoaded(final String url) {
},
mRedirectUri,
getSwitchBrowserCoordinator().getSwitchBrowserRequestHandler(),
mUtid
mUtid,
isWebViewWebcpEnabledInBrokerlessCase
);
setUpWebView(view, mAADWebViewClient);
mAADWebViewClient.initializeAuthUxJavaScriptApi(mWebView, mAuthorizationRequestUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ public class AzureActiveDirectoryWebViewClient extends OAuth2WebViewClient {
private HashMap<String, String> mRequestHeaders;
private String mRequestUrl;
private boolean mInWebCpFlow = false;
private boolean mAuthUxJavaScriptInterfaceAdded = false;
// Determines whether to handle WebCP requests in the WebView in brokerless scenarios.
private final boolean mIsWebViewWebCpEnabledInBrokerlessCase;


private final String mUtid;

Expand All @@ -143,12 +147,14 @@ public AzureActiveDirectoryWebViewClient(@NonNull final Activity activity,
@NonNull final OnPageLoadedCallback pageLoadedCallback,
@NonNull final String redirectUrl,
@NonNull final SwitchBrowserRequestHandler switchBrowserRequestHandler,
@Nullable final String utid) {
@Nullable final String utid,
final boolean isWebViewWebCpEnabledInBrokerlessCase) {
super(activity, completionCallback, pageLoadedCallback);
mRedirectUrl = redirectUrl;
mCertBasedAuthFactory = new CertBasedAuthFactory(activity);
mSwitchBrowserRequestHandler = switchBrowserRequestHandler;
mUtid = utid;
mIsWebViewWebCpEnabledInBrokerlessCase = isWebViewWebCpEnabledInBrokerlessCase;
}

/**
Expand Down Expand Up @@ -704,9 +710,9 @@ protected boolean isWebCpInWebviewFeatureEnabled(@NonNull final String originalU
final String methodTag = TAG + ":isWebCpInWebviewFeatureEnabled";
try {
if (!ProcessUtil.isRunningOnAuthService(getActivity().getApplicationContext())) {
// Enabling webcp in webview feature for brokered flows only for now.
Logger.info(methodTag, "Not running on AuthService, skipping WebCP in WebView feature check.");
return false;
mInWebCpFlow = mIsWebViewWebCpEnabledInBrokerlessCase;
Logger.info(methodTag, "Not running on AuthService, WebCP in WebView feature enabled? "+ mIsWebViewWebCpEnabledInBrokerlessCase);
return mInWebCpFlow;
}

final String homeTenantId = !StringUtil.isNullOrEmpty(mUtid)? mUtid : getHomeTenantIdFromUrl(originalUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ public void onPageLoaded(final String url) {
},
TEST_REDIRECT_URI,
Mockito.mock(SwitchBrowserRequestHandler.class),
"homeTenantId");
"homeTenantId",
false);
HashMap<String, String> dummyHeaders = new HashMap<>();
dummyHeaders.put("key", "value");
mWebViewClient.setRequestHeaders(dummyHeaders);
Expand Down Expand Up @@ -373,6 +374,46 @@ public void testLoadDeviceCaUrlInBrowserInBrokelessFlow() {
Mockito.verify(mockWebview, Mockito.never()).loadUrl(Mockito.anyString(), Mockito.any());
}

@Test
public void testLoadDeviceCaUrlInWebviewInBrokelessFlow() {
// Mocks
final WebView mockWebview = Mockito.mock(WebView.class);
final AzureActiveDirectoryWebViewClient mockWebViewClient = new AzureActiveDirectoryWebViewClient(
mActivity,
new IAuthorizationCompletionCallback() {
@Override
public void onChallengeResponseReceived(@NonNull RawAuthorizationResult response) {

}

@Override
public void setPKeyAuthStatus(boolean status) {
return;
}
},
new OnPageLoadedCallback() {
@Override
public void onPageLoaded(final String url) {
return;
}
},
TEST_REDIRECT_URI,
Mockito.mock(SwitchBrowserRequestHandler.class),
"homeTenantId",
true);
final IFlightsProvider mockFlightsProvider = Mockito.mock(IFlightsProvider.class);
when(mockFlightsProvider.isFlightEnabled(CommonFlight.ENABLE_WEB_CP_IN_WEBVIEW)).thenReturn(true);

final MockCommonFlightsManager mockCommonFlightsManager = new MockCommonFlightsManager();
mockCommonFlightsManager.setMockCommonFlightsProvider(mockFlightsProvider);
CommonFlightsManager.INSTANCE.initializeCommonFlightsManager(mockCommonFlightsManager);
// Actual call
mockWebViewClient.loadDeviceCaUrl(TEST_BROWSER_DEVICE_CA_URL_QUERY_STRING_PARAMETER, mockWebview);
// Verify
Mockito.verify(mockFlightsProvider, Mockito.never()).isFlightEnabled(Mockito.any());
Mockito.verify(mockWebview).loadUrl(Mockito.anyString(), Mockito.any());
}

@Test
public void testProcessCloudRedirectAndPrtHeaderInternalSuccess() {
ReAttachPrtHeaderHandler mockCrossCloudChallengeHandler = Mockito.mock(ReAttachPrtHeaderHandler.class);
Expand Down Expand Up @@ -431,7 +472,8 @@ public void onPageLoaded(final String url) {
},
TEST_REDIRECT_URI,
Mockito.mock(SwitchBrowserRequestHandler.class),
"homeTenantId");
"homeTenantId",
false);
mWebViewClient.shouldOverrideUrlLoading(mMockWebView, TEST_PASSKEY_REDIRECT_URL);
} catch (ClassCastException e) {
Assert.fail("Failure is not expected. The class checks should have prevented this." + e);
Expand All @@ -453,7 +495,8 @@ public void testOnReceivedSslError_Legacy() {
url -> {},
TEST_REDIRECT_URI,
Mockito.mock(SwitchBrowserRequestHandler.class),
"homeTenantId");
"homeTenantId",
false);
final WebView mockWebView = new WebView(mContext);
mockWebView.setWebViewClient(mockWebViewClient);

Expand Down Expand Up @@ -481,7 +524,8 @@ public void testOnReceivedSslError() {
url -> {},
TEST_REDIRECT_URI,
Mockito.mock(SwitchBrowserRequestHandler.class),
"homeTenantId"
"homeTenantId",
false
);
final WebView mockWebView = new WebView(mContext);
mockWebView.setWebViewClient(mockWebViewClient);
Expand Down Expand Up @@ -522,7 +566,8 @@ private void testProcessWebsiteRequest_BrowserRedirect() {
url -> {},
TEST_REDIRECT_URI,
Mockito.mock(SwitchBrowserRequestHandler.class),
"homeTenantId"
"homeTenantId",
false
));
final WebView mockWebView = Mockito.mock(WebView.class);

Expand All @@ -549,7 +594,8 @@ private void testProcessWebsiteRequest_DeviceCaRequest() {
url -> {},
TEST_REDIRECT_URI,
Mockito.mock(SwitchBrowserRequestHandler.class),
"homeTenantId"
"homeTenantId",
false
));
final WebView mockWebView = Mockito.mock(WebView.class);

Expand Down Expand Up @@ -581,7 +627,8 @@ private void testProcessWebsiteRequest_WebCpPlaystoreRedirect() {
url -> {},
TEST_REDIRECT_URI,
Mockito.mock(SwitchBrowserRequestHandler.class),
"homeTenantId"
"homeTenantId",
false
);
final WebView mockWebView = Mockito.mock(WebView.class);

Expand Down Expand Up @@ -620,7 +667,8 @@ private void testProcessWebsiteRequest_ExceptionHandling() {
url -> {},
TEST_REDIRECT_URI,
Mockito.mock(SwitchBrowserRequestHandler.class),
"homeTenantId"
"homeTenantId",
false
));
final WebView mockWebView = Mockito.mock(WebView.class);

Expand Down
Loading