Skip to content

Commit 389a192

Browse files
authored
Edge TB: Expose WebApps APIs, Fixes AB#3409879 (#2793)
### Summary: In this PR, we: - Expose the WebApp APIs via BrokerMsalController. OneAuth is already using this class to call similar Edge APIs. - getSupportedWebAppContracts(String minBrokerProtocolVersion): this method is called by OneAuth to make sure that the broker can handle the request. - executeWebAppRequest(String Request, String minBrokerProtocolVersion): this method handles requests for GetToken, GetCookies, and SignOut. - Implement the bundle helper methods for creating the bundle and extracting the results from the result bundle. - Adds the bundle keys to AuthenticationConstants, where both common and broker can access them. Related broker PR: AzureAD/ad-accounts-for-android#3256 [AB#3409879](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3409879/)
1 parent c01f461 commit 389a192

File tree

6 files changed

+211
-2
lines changed

6 files changed

+211
-2
lines changed

changelog.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ vNext
55
- [MINOR] Add OTel Benchmarker (#2786)
66
- [MINOR] WebApps AccountId Registry (#2787)
77
- [MINOR] Take flight value for whether to show webcp flow in weview or not in brokerless scenarios. (#2784)
8+
- [MINOR] getAllSsoTokens method for Edge (#2774)
9+
- [MINOR] WebApps AccountId Registry (#2787)
10+
- [MINOR] Expose WebApps APIs (#2793)
811
- [MINOR] Add domainHint support to authorization request (#2792)
912

1013
Version 23.0.2
@@ -20,7 +23,6 @@ Version 23.0.2
2023
- [MINOR] SDK now handles SMS as strong authentication method #2766
2124
- [MINOR] Added error handling when webcp redirects have browser protocol #2767
2225
- [PATCH] Fix for app link redirect from CCT due to forced browser preference (#2775)
23-
- [MINOR] getAllSsoTokens method for Edge (#2774)
2426

2527
Version 22.1.3
2628
----------

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,26 @@ public static String computeMaxHostBrokerProtocol() {
13761376
*/
13771377
public static final String BROKER_GENERATE_ALL_SSO_TOKENS_RESULT = "broker_generate_all_sso_tokens";
13781378

1379+
/**
1380+
* String for broker webapps get contracts result.
1381+
*/
1382+
public static final String BROKER_WEBAPPS_GET_CONTRACTS_RESULT = "contracts";
1383+
1384+
/**
1385+
* String for broker webapps error result.
1386+
*/
1387+
public static final String BROKER_WEB_APPS_ERROR = "error";
1388+
1389+
/**
1390+
* String for broker webapps request.
1391+
*/
1392+
public static final String BROKER_WEB_APPS_REQUEST = "request";
1393+
1394+
/**
1395+
* String for broker webapps response.
1396+
*/
1397+
public static final String BROKER_WEB_APPS_RESPONSE = "response";
1398+
13791399
/**
13801400
* String for generate shr result.
13811401
*/

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

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,119 @@ public void putValueInSuccessEvent(@NonNull final ApiEndEvent event,
13651365
});
13661366
}
13671367

1368+
/**
1369+
* Get supported web app contracts from broker.
1370+
*
1371+
* @param minBrokerProtocolVersion minimum broker protocol version the caller requires.
1372+
* @throws BaseException
1373+
*/
1374+
public String getSupportedWebAppContracts(@NonNull final String minBrokerProtocolVersion) throws BaseException {
1375+
return getBrokerOperationExecutor().execute(null,
1376+
new BrokerOperation<String>() {
1377+
private String negotiatedBrokerProtocolVersion;
1378+
1379+
@Override
1380+
public void performPrerequisites(@NonNull final IIpcStrategy strategy) throws BaseException {
1381+
negotiatedBrokerProtocolVersion = hello(strategy, minBrokerProtocolVersion);
1382+
}
1383+
1384+
@NonNull
1385+
@Override
1386+
public BrokerOperationBundle getBundle() throws ClientException {
1387+
return new BrokerOperationBundle(
1388+
BrokerOperationBundle.Operation.BROKER_WEBAPPS_API_GET_SUPPORTED_WEB_APPS_CONTRACTS,
1389+
mActiveBrokerPackageName,
1390+
mRequestAdapter.getRequestBundleForGetSupportedWebAppContracts(negotiatedBrokerProtocolVersion, minBrokerProtocolVersion)
1391+
);
1392+
}
1393+
1394+
@NonNull
1395+
@Override
1396+
public String extractResultBundle(
1397+
@Nullable final Bundle resultBundle) throws BaseException {
1398+
if (resultBundle == null) {
1399+
throw mResultAdapter.getExceptionForEmptyResultBundle();
1400+
}
1401+
verifyBrokerVersionIsSupported(resultBundle, minBrokerProtocolVersion);
1402+
return mResultAdapter.getSupportedWebAppsContractFromBundle(resultBundle);
1403+
}
1404+
1405+
@NonNull
1406+
@Override
1407+
public String getMethodName() {
1408+
return ":getSupportedWebAppContracts";
1409+
}
1410+
1411+
@Nullable
1412+
@Override
1413+
public String getTelemetryApiId() {
1414+
return null;
1415+
}
1416+
1417+
@Override
1418+
public void putValueInSuccessEvent(@NonNull final ApiEndEvent event,
1419+
@NonNull final String result) {
1420+
}
1421+
});
1422+
}
1423+
1424+
/**
1425+
* Execute web app request in broker.
1426+
*
1427+
* @param request request string
1428+
* @param minBrokerProtocolVersion minimum broker protocol version the caller requires.
1429+
* @throws BaseException
1430+
*/
1431+
public String executeWebAppRequest(@NonNull final String request,
1432+
@NonNull final String minBrokerProtocolVersion) throws BaseException {
1433+
return getBrokerOperationExecutor().execute(null,
1434+
new BrokerOperation<String>() {
1435+
private String negotiatedBrokerProtocolVersion;
1436+
1437+
@Override
1438+
public void performPrerequisites(@NonNull final IIpcStrategy strategy) throws BaseException {
1439+
negotiatedBrokerProtocolVersion = hello(strategy, minBrokerProtocolVersion);
1440+
}
1441+
1442+
@NonNull
1443+
@Override
1444+
public BrokerOperationBundle getBundle() throws ClientException {
1445+
return new BrokerOperationBundle(
1446+
BrokerOperationBundle.Operation.BROKER_WEBAPPS_API_EXECUTE_WEB_APPS_REQUEST,
1447+
mActiveBrokerPackageName,
1448+
mRequestAdapter.getRequestBundleForExecuteWebAppRequest(request,negotiatedBrokerProtocolVersion, minBrokerProtocolVersion)
1449+
);
1450+
}
1451+
1452+
@NonNull
1453+
@Override
1454+
public String extractResultBundle(@Nullable final Bundle resultBundle) throws BaseException {
1455+
if (resultBundle == null) {
1456+
throw mResultAdapter.getExceptionForEmptyResultBundle();
1457+
}
1458+
verifyBrokerVersionIsSupported(resultBundle, minBrokerProtocolVersion);
1459+
return mResultAdapter.getExecuteWebAppRequestResultFromBundle(resultBundle);
1460+
}
1461+
1462+
@NonNull
1463+
@Override
1464+
public String getMethodName() {
1465+
return ":executeWebAppRequest";
1466+
}
1467+
1468+
@Nullable
1469+
@Override
1470+
public String getTelemetryApiId() {
1471+
return null;
1472+
}
1473+
1474+
@Override
1475+
public void putValueInSuccessEvent(@NonNull final ApiEndEvent event,
1476+
@NonNull final String result) {
1477+
}
1478+
});
1479+
}
1480+
13681481
/**
13691482
* Checks if the account returns is a MSA Account and sets single on state in cache
13701483
*/

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker.AUTH_SCHEME_PARAMS_POP;
3030
import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker.BROKER_REQUEST_V2;
3131
import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker.BROKER_REQUEST_V2_COMPRESSED;
32+
import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker.BROKER_WEB_APPS_REQUEST;
3233
import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker.CALLER_INFO_UID;
3334
import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker.CAN_FOCI_APPS_CONSTRUCT_ACCOUNTS_FROM_PRT_ID_TOKEN_KEY;
3435
import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker.CLIENT_ADVERTISED_MAXIMUM_BP_VERSION_KEY;
@@ -580,6 +581,37 @@ public Bundle getRequestBundleForAadDeviceIdRequest(
580581
);
581582
}
582583

584+
/**
585+
* Method to construct a request bundle for broker getSupportedWebAppContracts request.
586+
*
587+
* @return request Bundle
588+
*/
589+
public @NonNull Bundle getRequestBundleForGetSupportedWebAppContracts(@NonNull final String negotiatedBrokerProtocolVersion,
590+
@NonNull final String requiredBrokerProtocolVersion) {
591+
final Bundle requestBundle = new Bundle();
592+
requestBundle.putString(AuthenticationConstants.Broker.NEGOTIATED_BP_VERSION_KEY, negotiatedBrokerProtocolVersion);
593+
addRequiredBrokerProtocolVersionToRequestBundle(requestBundle, requiredBrokerProtocolVersion);
594+
return requestBundle;
595+
}
596+
597+
/**
598+
* Method to construct a request bundle for broker executeWebAppRequest request.
599+
*
600+
* @param request input request
601+
* @param negotiatedBrokerProtocolVersion protocol version returned by broker hello.
602+
* @param requiredBrokerProtocolVersion protocol version required by the client.
603+
* @return request Bundle
604+
*/
605+
public Bundle getRequestBundleForExecuteWebAppRequest(@NonNull final String request,
606+
@NonNull final String negotiatedBrokerProtocolVersion,
607+
@NonNull final String requiredBrokerProtocolVersion) {
608+
final Bundle bundle = new Bundle();
609+
bundle.putString(AuthenticationConstants.Broker.NEGOTIATED_BP_VERSION_KEY, negotiatedBrokerProtocolVersion);
610+
bundle.putString(BROKER_WEB_APPS_REQUEST, request);
611+
addRequiredBrokerProtocolVersionToRequestBundle(bundle, requiredBrokerProtocolVersion);
612+
return bundle;
613+
}
614+
583615
private boolean getMultipleCloudsSupported(@NonNull final TokenCommandParameters parameters) {
584616
if (parameters.getAuthority() instanceof AzureActiveDirectoryAuthority) {
585617
final AzureActiveDirectoryAuthority authority = (AzureActiveDirectoryAuthority) parameters.getAuthority();

common/src/main/java/com/microsoft/identity/common/internal/result/MsalBrokerResultAdapter.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker.BROKER_GENERATE_SSO_TOKEN_RESULT;
3232
import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker.BROKER_PACKAGE_NAME;
3333
import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker.BROKER_RESULT_V2_COMPRESSED;
34+
import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker.BROKER_WEBAPPS_GET_CONTRACTS_RESULT;
35+
import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker.BROKER_WEB_APPS_ERROR;
36+
import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker.BROKER_WEB_APPS_RESPONSE;
3437
import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker.HELLO_ERROR_CODE;
3538
import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker.HELLO_ERROR_MESSAGE;
3639
import static com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker.NEGOTIATED_BP_VERSION_KEY;
@@ -115,7 +118,7 @@ public class MsalBrokerResultAdapter implements IBrokerResultAdapter {
115118
public static final Gson GSON = new Gson();
116119

117120
private static final String DCF_NOT_SUPPORTED_ERROR = "deviceCodeFlowAuthRequest() not supported in BrokerMsalController";
118-
121+
private static final String WEBAPPS_ENTRY_IS_NULL_ERROR = "WebApps entry in the bundle is null";
119122
interface IBooleanCallback {
120123
boolean getResult();
121124
}
@@ -1044,4 +1047,38 @@ public AadDeviceIdRecord aadDeviceIdRecordFromBundle(@NonNull final Bundle resul
10441047
}
10451048
return aadDeviceIdRecord;
10461049
}
1050+
1051+
/**
1052+
* Gets the supported web apps contract string from the result bundle.
1053+
* @param resultBundle The result bundle from the broker.
1054+
*/
1055+
@NonNull
1056+
public String getSupportedWebAppsContractFromBundle(@NonNull final Bundle resultBundle) throws ClientException {
1057+
final String result = resultBundle.getString(BROKER_WEBAPPS_GET_CONTRACTS_RESULT);
1058+
if (result == null) {
1059+
throw new ClientException(INVALID_BROKER_BUNDLE, WEBAPPS_ENTRY_IS_NULL_ERROR + " for " + BROKER_WEBAPPS_GET_CONTRACTS_RESULT);
1060+
}
1061+
return result;
1062+
}
1063+
1064+
/**
1065+
* Gets the execute web app request result string from the result bundle.
1066+
* @param resultBundle The result bundle from the broker.
1067+
*/
1068+
@NonNull
1069+
public String getExecuteWebAppRequestResultFromBundle(@NonNull final Bundle resultBundle) throws ClientException {
1070+
// Expect either success payload or error fields reused from BrokerResult
1071+
if (resultBundle.containsKey(BROKER_WEB_APPS_ERROR)) {
1072+
final String result = resultBundle.getString(BROKER_WEB_APPS_ERROR);
1073+
if (result == null) {
1074+
throw new ClientException(INVALID_BROKER_BUNDLE, WEBAPPS_ENTRY_IS_NULL_ERROR + " for " + BROKER_WEB_APPS_ERROR);
1075+
}
1076+
return result;
1077+
}
1078+
final String result = resultBundle.getString(BROKER_WEB_APPS_RESPONSE);
1079+
if (result == null) {
1080+
throw new ClientException(INVALID_BROKER_BUNDLE, WEBAPPS_ENTRY_IS_NULL_ERROR + " for " + BROKER_WEB_APPS_RESPONSE);
1081+
}
1082+
return result;
1083+
}
10471084
}

common4j/src/main/com/microsoft/identity/common/java/exception/ErrorStrings.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,11 @@ private ErrorStrings() {
470470
*/
471471
public static final String ACTIVITY_NOT_FOUND = "activity_not_found";
472472

473+
/**
474+
* All web app sign out attempts failed.
475+
*/
476+
public static final String ALL_WEBAPP_SIGN_OUTS_FAILED = "all_webapp_sign_outs_failed";
477+
473478
/**
474479
* A generic error code used when no other error code is applicable.
475480
*/

0 commit comments

Comments
 (0)