Skip to content

Commit 978eb83

Browse files
committed
Refactor onboarding blob extraction to follow getBrokerPerformanceMetricsFromBundle pattern
The previous inline try/catch in getAcquireTokenResultFromResultBundle was visually inconsistent with neighboring extractors (setBrokerPerformanceMetrics, setBrokerAppVersion, setBrokerAppPackageName). Extracts the deserialization + exception handling into a dedicated getOnboardingBlobFromBundle helper that mirrors the BrokerPerformanceMetrics pattern, leaving the call site as a clean two-line if-non-null guard.
1 parent 72adf81 commit 978eb83

1 file changed

Lines changed: 23 additions & 12 deletions

File tree

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

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,25 @@ public BrokerPerformanceMetrics getBrokerPerformanceMetricsFromBundle(@NonNull f
565565
}
566566
}
567567

568+
/**
569+
* Extracts the onboarding telemetry blob (JSON string) from the result bundle.
570+
* Best-effort: returns null if the bundle cannot be deserialized into a BrokerResult
571+
* or if no blob is present. Telemetry failures must never fail an otherwise-successful
572+
* auth result. Blob contents are not logged (may carry sessionCorrelationId).
573+
*/
574+
@Nullable
575+
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
576+
public String getOnboardingBlobFromBundle(@NonNull final Bundle resultBundle) {
577+
final String methodTag = TAG + ":getOnboardingBlobFromBundle";
578+
try {
579+
final BrokerResult brokerResult = brokerResultFromBundle(resultBundle);
580+
return brokerResult.getOnboardingBlob();
581+
} catch (final ClientException e) {
582+
Logger.warn(methodTag, "Failed to extract onboarding blob from broker result: " + e.getErrorCode());
583+
return null;
584+
}
585+
}
586+
568587
@NonNull
569588
@Override
570589
public AcquirePrtSsoTokenResult getAcquirePrtSsoTokenResultFromBundle(Bundle resultBundle) {
@@ -1015,7 +1034,6 @@ public AcquireTokenResult getDeviceCodeFlowTokenResultFromResultBundle(@NonNull
10151034

10161035
public @NonNull
10171036
AcquireTokenResult getAcquireTokenResultFromResultBundle(@NonNull final Bundle resultBundle) throws BaseException {
1018-
final String methodTag = TAG + ":getAcquireTokenResultFromResultBundle";
10191037
final MsalBrokerResultAdapter resultAdapter = new MsalBrokerResultAdapter();
10201038
if (resultBundle.getBoolean(AuthenticationConstants.Broker.BROKER_REQUEST_V2_SUCCESS)) {
10211039
final AcquireTokenResult acquireTokenResult = new AcquireTokenResult();
@@ -1040,17 +1058,10 @@ AcquireTokenResult getAcquireTokenResultFromResultBundle(@NonNull final Bundle r
10401058
);
10411059
}
10421060

1043-
// Extract onboarding blob from BrokerResult if present. Best-effort — telemetry
1044-
// failures must never fail an otherwise-successful auth result. Logged at warn so
1045-
// diagnosing IPC/regression issues remains possible. Blob contents are not logged
1046-
// (may contain sessionCorrelationId).
1047-
try {
1048-
final BrokerResult brokerResult = resultAdapter.brokerResultFromBundle(resultBundle);
1049-
if (brokerResult.getOnboardingBlob() != null) {
1050-
acquireTokenResult.setOnboardingBlob(brokerResult.getOnboardingBlob());
1051-
}
1052-
} catch (final ClientException e) {
1053-
Logger.warn(methodTag, "Failed to extract onboarding blob from broker result: " + e.getErrorCode());
1061+
// Set onboarding telemetry blob if present (best-effort; never fails the result).
1062+
final String onboardingBlob = resultAdapter.getOnboardingBlobFromBundle(resultBundle);
1063+
if (onboardingBlob != null) {
1064+
acquireTokenResult.setOnboardingBlob(onboardingBlob);
10541065
}
10551066

10561067
return acquireTokenResult;

0 commit comments

Comments
 (0)