Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ public abstract class AzureActiveDirectoryAudience {
public static final String ALL = "common";
public static final String MSA_MEGA_TENANT_ID = "9188040d-6c67-4c5b-b112-36a304b66dad";

// The values here are audience values reported in telemetry
// rather than the values used to send to eSTS.
public static class TelemetryConstants {
public static final String MSA_AUDIENCE_FOR_REPORTING = "MSA";
public static final String COMMON_AUDIENCE_FOR_REPORTING = "COMMON";
public static final String AAD_AUDIENCE_FOR_REPORTING = "AAD";
public static final String UNKNOWN_AUDIENCE_FOR_REPORTING = "UNKNOWN";
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should move this and the method to broker itself. Telemetry is for broker only.

At this layer it's extra stuff present in AzureActiveDirectoryAudience

Copy link
Contributor

Choose a reason for hiding this comment

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

+1



public String getCloudUrl() {
if (mCloudUrl == null) {
return AzureActiveDirectory.getDefaultCloudUrl();
Expand Down Expand Up @@ -154,6 +164,32 @@ public void setTenantId(String tenantId) {
mTenantId = tenantId;
}

/**
* Determines the audience type (MSA, Common, AAD, or Unknown) from the given
* {@link AzureActiveDirectoryAuthority}.
*
* @param authority The authority from which the audience is derived.
* @return The audience type: "MSA", "Common", "AAD", or "Unknown".
*/
public static String getAudienceFromAuthority( final AzureActiveDirectoryAuthority authority) {

if (authority == null || StringUtil.isNullOrEmpty(authority.getAudience().getTenantId())) {
return TelemetryConstants.UNKNOWN_AUDIENCE_FOR_REPORTING;
}

final String audienceToCheck = authority.getAudience().mTenantId.toLowerCase(Locale.ROOT);

if (audienceToCheck.equals(CONSUMERS) || audienceToCheck.equals(MSA_MEGA_TENANT_ID)) {
return TelemetryConstants.MSA_AUDIENCE_FOR_REPORTING;
}
else if (audienceToCheck.equals(ALL)) {
return TelemetryConstants.COMMON_AUDIENCE_FOR_REPORTING;
}
else {
return TelemetryConstants.AAD_AUDIENCE_FOR_REPORTING;
}
}

public static AzureActiveDirectoryAudience getAzureActiveDirectoryAudience(final String cloudUrl,
final String tenantId) {
final String methodName = ":getAzureActiveDirectoryAudience";
Expand Down