Skip to content

Use Broker Content Provider for number match, Fixes AB#3308440 #2699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 1, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,16 @@ public static String computeMaxHostBrokerProtocol() {
*/
public static final String GET_FLIGHTS_RESULT = "active_flights";

/**
* The Bundle key name of the result of the number match operation.
*/
public static final String GET_NUMBER_MATCH_RESULT = "number_match";

/**
* SessionID for the number match operation.
*/
public static final String SESSION_ID = "session_id";

/**
* Time out for the AccountManager's remove account operation in broker.
*/
Expand Down Expand Up @@ -1656,6 +1666,7 @@ public enum API {
BROKER_UPDATE_BRT(BROKER_API_UPDATE_BRT_PATH, BROKER_VERSION_1, null),
BROKER_SET_FLIGHTS(BROKER_API_SET_FLIGHTS_PATH, BROKER_VERSION_3, null),
BROKER_GET_FLIGHTS(BROKER_API_GET_FLIGHTS_PATH, BROKER_VERSION_3, null),

GET_SSO_TOKEN(GET_SSO_TOKEN_PATH, null, VERSION_7),
UNKNOWN(null, null, null),
DEVICE_REGISTRATION_PROTOCOLS(DEVICE_REGISTRATION_PROTOCOLS_PATH, null, null),
Expand All @@ -1674,7 +1685,9 @@ public enum API {
WEBAPPS_GET_SUPPORTED_WEB_APPS_CONTRACTS(WEBAPPS_GET_SUPPORTED_WEB_APPS_CONTRACTS_PATH, null, null),
WEBAPPS_EXECUTE_WEB_APPS_REQUEST(WEBAPPS_EXECUTE_WEB_APPS_REQUEST_PATH, null, null),
PROVISION_RESOURCE_ACCOUNT(PROVISION_RESOURCE_ACCOUNT_PATH, null, null),
GET_AAD_DEVICE_ID(GET_AAD_DEVICE_ID_PATH, null, null);
GET_AAD_DEVICE_ID(GET_AAD_DEVICE_ID_PATH, null, null),
BROKER_GET_NUMBER_MATCH(BROKER_API_GET_NUMBER_MATCH_PATH, BROKER_VERSION_3, null);


/**
* The content provider path that the API exists behind.
Expand Down Expand Up @@ -1794,6 +1807,11 @@ public String getMsalVersion(){
*/
public static final String BROKER_API_GET_FLIGHTS_PATH = "/brokerApi/getFlights";

/**
* Broker api path constant for getting number match.
*/
public static final String BROKER_API_GET_NUMBER_MATCH_PATH = "/brokerApi/getNumberMatch";

/**
* ContentProvider path for retrieving Broker Discovery Metadata.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import com.google.gson.JsonSyntaxException
import com.google.gson.stream.MalformedJsonException
import com.microsoft.identity.common.adal.internal.AuthenticationConstants
import com.microsoft.identity.common.internal.numberMatch.NumberMatchHelper
import com.microsoft.identity.common.java.opentelemetry.AttributeName
import com.microsoft.identity.common.java.opentelemetry.SpanExtension
import com.microsoft.identity.common.logging.Logger
import java.net.MalformedURLException
import java.net.URL
Expand Down Expand Up @@ -115,10 +117,11 @@ class AuthUxJavaScriptInterface {
"Correlation ID during JavaScript Call: [${payloadObject.correlationId}]"
)


// TODO: Leaving these here, as these will be relevant for next WebCP feature
// val actionName = payloadObject.actionName
// val actionComponent = payloadObject.actionComponent
val span = SpanExtension.current()
val actionName = payloadObject.actionName
span.setAttribute(AttributeName.authux_js_action_name.name, actionName)
val actionComponent = payloadObject.actionComponent
span.setAttribute(AttributeName.authux_js_action_component.name, actionComponent)

val parameters = payloadObject.params
if (parameters == null) {
Expand All @@ -127,6 +130,9 @@ class AuthUxJavaScriptInterface {
}

val operation = parameters.operation
if (operation != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what cases would this be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will let @fadidurah answer since it is a part of his changes.

Copy link
Contributor

@fadidurah fadidurah Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As part of the AuthUx platform agnostic JS API discussion, operation is not a mandatory field at this time, future usages of this interface may not have this field, and may only rely on action_name and action_component

span.setAttribute(AttributeName.authux_js_operation.name, operation)
}

Logger.info(methodTag, "Function name: [$operation]")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public enum Operation {
BROKER_WEBAPPS_API_GET_SUPPORTED_WEB_APPS_CONTRACTS(API.WEBAPPS_GET_SUPPORTED_WEB_APPS_CONTRACTS, null),
BROKER_WEBAPPS_API_EXECUTE_WEB_APPS_REQUEST(API.WEBAPPS_EXECUTE_WEB_APPS_REQUEST, null),
PROVISION_RESOURCE_ACCOUNT(API.PROVISION_RESOURCE_ACCOUNT, null),
GET_AAD_DEVICE_ID(API.GET_AAD_DEVICE_ID, null);
GET_AAD_DEVICE_ID(API.GET_AAD_DEVICE_ID, null),
BROKER_GET_NUMBER_MATCH(API.BROKER_GET_NUMBER_MATCH, null);

final API mContentApi;
final String mAccountManagerOperation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
// THE SOFTWARE.
package com.microsoft.identity.common.internal.numberMatch

import com.microsoft.identity.common.java.opentelemetry.AttributeName
import com.microsoft.identity.common.java.opentelemetry.SpanExtension
import com.microsoft.identity.common.logging.Logger

/**
Expand All @@ -41,8 +43,6 @@ class NumberMatchHelper {
companion object {
val TAG = NumberMatchHelper::class.java.simpleName
val numberMatchMap: HashMap<String, String> = HashMap()
const val SESSION_ID_ATTRIBUTE_NAME = "sessionID"
const val NUMBER_MATCH_ATTRIBUTE_NAME = "numberMatch"

/**
* Method to add a key:value pair of sessionID:numberMatch to static hashmap. This hashmap will be accessed
Expand All @@ -53,15 +53,19 @@ class NumberMatchHelper {
Logger.info(methodTag,
"Adding entry in NumberMatch hashmap for session ID: $sessionId")

val span = SpanExtension.current()

// If both parameters are non-null, add a new entry to the hashmap
if (sessionId != null && numberMatch != null) {
numberMatchMap[sessionId] = numberMatch
span.setAttribute(AttributeName.stored_number_match_entry.name, true)
}
// If either parameter is null, do nothing
else {
Logger.warn(methodTag,
"Either session ID or number match is null. Nothing to add for number match."
)
span.setAttribute(AttributeName.stored_number_match_entry.name, false)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,5 +384,25 @@ public enum AttributeName {
* Records the if webview received an SSL error and
* corresponding primary error code.
*/
web_view_ssl_primary_error_code
web_view_ssl_primary_error_code,

/**
* Record action name from Webview JavaScript Payload
*/
authux_js_action_name,

/**
* Record action component from Webview JavaScript Payload
*/
authux_js_action_component,

/**
* Record operation name from Webview JavaScript Payload
*/
authux_js_operation,

/**
* Record whether or not the request stored a number match entry.
*/
stored_number_match_entry
}