Skip to content

Commit 0ea350f

Browse files
authored
Update logging for Runtime Broker (#4318)
Update WamAdapters.cs
1 parent 3e13383 commit 0ea350f

File tree

1 file changed

+22
-22
lines changed
  • src/client/Microsoft.Identity.Client/Platforms/Features/RuntimeBroker

1 file changed

+22
-22
lines changed

src/client/Microsoft.Identity.Client/Platforms/Features/RuntimeBroker/WamAdapters.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ private static MsalException CreateExceptionFromWamError(
6363
long errorCode = authResult.Error.ErrorCode;
6464
string errorMessage;
6565

66-
logger.Info("[WamBroker] Processing WAM exception");
67-
logger.Verbose(() => $"[WamBroker] TelemetryData: {authResult.TelemetryData}");
66+
logger.Info("[RuntimeBroker] Processing WAM exception");
67+
logger.Verbose(() => $"[RuntimeBroker] TelemetryData: {authResult.TelemetryData}");
6868

6969
switch ((ResponseStatus)authResult.Error.Status)
7070
{
7171
case ResponseStatus.UserCanceled:
72-
logger.Error($"[WamBroker] {MsalError.AuthenticationCanceledError} {MsalErrorMessage.AuthenticationCanceled}");
72+
logger.Error($"[RuntimeBroker] {MsalError.AuthenticationCanceledError} {MsalErrorMessage.AuthenticationCanceled}");
7373
var clientEx = new MsalClientException(MsalError.AuthenticationCanceledError, MsalErrorMessage.AuthenticationCanceled);
7474
return clientEx;
7575
case ResponseStatus.InteractionRequired:
@@ -79,7 +79,7 @@ private static MsalException CreateExceptionFromWamError(
7979
$" Error Code: {errorCode} \n" +
8080
$" Error Message: {authResult.Error.Context} \n" +
8181
$" Internal Error Code: {internalErrorCode} \n";
82-
logger.Error($"[WamBroker] {MsalError.FailedToAcquireTokenSilentlyFromBroker} {errorMessage}");
82+
logger.Error($"[RuntimeBroker] {MsalError.FailedToAcquireTokenSilentlyFromBroker} {errorMessage}");
8383
var ex = new MsalUiRequiredException(MsalError.FailedToAcquireTokenSilentlyFromBroker, errorMessage);
8484
return ex;
8585

@@ -94,7 +94,7 @@ private static MsalException CreateExceptionFromWamError(
9494
$" Possible causes: \n" +
9595
$"- Invalid redirect uri - ensure you have configured the following url in the application registration in Azure Portal: " +
9696
$"{GetExpectedRedirectUri(authenticationRequestParameters.AppConfig.ClientId)} \n";
97-
logger.Error($"[WamBroker] WAM_provider_error_{errorCode} {errorMessage}");
97+
logger.Error($"[RuntimeBroker] WAM_provider_error_{errorCode} {errorMessage}");
9898
serviceException = new MsalServiceException($"WAM_provider_error_{errorCode}", errorMessage);
9999
serviceException.IsRetryable = false;
100100
return serviceException;
@@ -110,14 +110,14 @@ private static MsalException CreateExceptionFromWamError(
110110
$" Internal Error Code: {internalErrorCode} \n" +
111111
$" Possible cause: no Internet connection ";
112112

113-
logger.Error($"[WamBroker] WAM_network_error_{errorCode} {errorMessage}");
113+
logger.Error($"[RuntimeBroker] WAM_network_error_{errorCode} {errorMessage}");
114114
serviceException = new MsalServiceException(errorCode.ToString(), errorMessage);
115115
serviceException.IsRetryable = true;
116116
return serviceException;
117117

118118
default:
119119
errorMessage = $"Unknown {authResult.Error} (error code {errorCode}) (internal error code {internalErrorCode})";
120-
logger.Verbose(() => $"[WamBroker] {MsalError.UnknownBrokerError} {errorMessage}");
120+
logger.Verbose(() => $"[RuntimeBroker] {MsalError.UnknownBrokerError} {errorMessage}");
121121
var ex2 = new MsalServiceException(MsalError.UnknownBrokerError, errorMessage);
122122
return ex2;
123123
}
@@ -144,12 +144,12 @@ public static NativeInterop.AuthParameters GetCommonAuthParameters(
144144
if (!ScopeHelper.HasNonMsalScopes(authenticationRequestParameters.Scope))
145145
{
146146
authParams.RequestedScopes = ScopeHelper.GetMsalRuntimeScopes();
147-
logger.Verbose(() => "[WamBroker] No scopes were passed in the request. Adding default scopes.");
147+
logger.Verbose(() => "[RuntimeBroker] No scopes were passed in the request. Adding default scopes.");
148148
}
149149
else
150150
{
151151
authParams.RequestedScopes = string.Join(" ", authenticationRequestParameters.Scope);
152-
logger.Verbose(() => "[WamBroker] Scopes were passed in the request.");
152+
logger.Verbose(() => "[RuntimeBroker] Scopes were passed in the request.");
153153
}
154154

155155
//WAM redirect URi does not need to be configured by the user
@@ -193,7 +193,7 @@ public static NativeInterop.AuthParameters GetCommonAuthParameters(
193193

194194
AddPopParams(authenticationRequestParameters, authParams);
195195

196-
logger.Verbose(() => "[WamBroker] Acquired Common Auth Parameters.");
196+
logger.Verbose(() => "[RuntimeBroker] Acquired Common Auth Parameters.");
197197

198198
return authParams;
199199
}
@@ -221,7 +221,7 @@ private static void AddPopParams(AuthenticationRequestParameters authenticationR
221221
// if PopAuthenticationConfiguration is set, proof of possession will be performed via the runtime broker
222222
if (authenticationRequestParameters.PopAuthenticationConfiguration != null)
223223
{
224-
authenticationRequestParameters.RequestContext.Logger.Info("[WamBroker] Proof-of-Possession is configured. Using Proof-of-Possession with broker request. ");
224+
authenticationRequestParameters.RequestContext.Logger.Info("[RuntimeBroker] Proof-of-Possession is configured. Using Proof-of-Possession with broker request. ");
225225
authParams.PopParams.HttpMethod = authenticationRequestParameters.PopAuthenticationConfiguration.HttpMethod?.Method;
226226
authParams.PopParams.UriHost = authenticationRequestParameters.PopAuthenticationConfiguration.HttpHost;
227227
authParams.PopParams.UriPath = authenticationRequestParameters.PopAuthenticationConfiguration.HttpPath;
@@ -247,12 +247,12 @@ private static void SetMSALIdentityProvider(
247247

248248
if (tenantObjectId.Equals(Constants.MsaTenantId, StringComparison.OrdinalIgnoreCase))
249249
{
250-
logger.Verbose(() => $"[WamBroker] MSALRuntime Identity provider set to MSA.");
250+
logger.Verbose(() => $"[RuntimeBroker] MSALRuntime Identity provider set to MSA.");
251251
authParams.Properties[MsalIdentityProvider] = IdentityProviderTypeMSA;
252252
}
253253
else
254254
{
255-
logger.Verbose(() => "[WamBroker] MSALRuntime Identity provider set to AAD");
255+
logger.Verbose(() => "[RuntimeBroker] MSALRuntime Identity provider set to AAD");
256256
authParams.Properties[MsalIdentityProvider] = IdentityProviderTypeAAD;
257257
}
258258
}
@@ -269,11 +269,11 @@ public static MsalTokenResponse HandleResponse(
269269
if (TokenReceivedFromWam(authResult, logger))
270270
{
271271
msalTokenResponse = ParseRuntimeResponse(authResult, authenticationRequestParameters, logger);
272-
logger.Verbose(() => "[WamBroker] Successfully retrieved token.");
272+
logger.Verbose(() => "[RuntimeBroker] Successfully retrieved token.");
273273
return msalTokenResponse;
274274
}
275275

276-
logger.Info($"[WamBroker] {errorMessage} {authResult.Error}");
276+
logger.Info($"[RuntimeBroker] {errorMessage} {authResult.Error}");
277277
MsalException ex = CreateExceptionFromWamError(authResult, authenticationRequestParameters, logger);
278278
ex = DecorateExceptionWithRuntimeErrorProperties(ex, authResult.Error);
279279
throw ex;
@@ -297,7 +297,7 @@ private static bool TokenReceivedFromWam(
297297
if (authResult.Error != null
298298
&& (ResponseStatus)authResult.Error.Status == ResponseStatus.UserSwitch)
299299
{
300-
logger.Info("[WamBroker] WAM response status account switch. Treating as success");
300+
logger.Info("[RuntimeBroker] WAM response status account switch. Treating as success");
301301
return true;
302302
}
303303

@@ -323,7 +323,7 @@ private static MsalTokenResponse ParseRuntimeResponse(
323323

324324
if (string.IsNullOrWhiteSpace(correlationId))
325325
{
326-
logger.Warning("[WamBroker] No correlation ID in response");
326+
logger.Warning("[RuntimeBroker] No correlation ID in response");
327327
correlationId = null;
328328
}
329329

@@ -356,13 +356,13 @@ private static MsalTokenResponse ParseRuntimeResponse(
356356
TokenSource = TokenSource.Broker
357357
};
358358

359-
logger.Info("[WamBroker] WAM response status success");
359+
logger.Info("[RuntimeBroker] WAM response status success");
360360

361361
return msalTokenResponse;
362362
}
363363
catch (MsalRuntimeException ex)
364364
{
365-
logger.ErrorPii($"[WamBroker] Could not acquire token using WAM. {ex.Message}", string.Empty);
365+
logger.ErrorPii($"[RuntimeBroker] Could not acquire token using WAM. {ex.Message}", string.Empty);
366366
throw new MsalServiceException("wam_failed", $"Could not acquire token using WAM. {ex.Message}");
367367
}
368368

@@ -439,7 +439,7 @@ private static void ToLogMessage(
439439
{
440440
// Create PII enabled string builder
441441
var builder = new StringBuilder(
442-
Environment.NewLine + "=== [WamBroker] Converting WAM Account to MSAL Account ===" +
442+
Environment.NewLine + "=== [RuntimeBroker] Converting WAM Account to MSAL Account ===" +
443443
Environment.NewLine);
444444

445445
builder.AppendLine($"wamAccount.AccountId: {wamAccount.AccountId}.");
@@ -450,7 +450,7 @@ private static void ToLogMessage(
450450

451451
// Create non PII enabled string builder
452452
builder = new StringBuilder(
453-
Environment.NewLine + "=== [WamBroker] Converting WAM Account to MSAL Account ===" +
453+
Environment.NewLine + "=== [RuntimeBroker] Converting WAM Account to MSAL Account ===" +
454454
Environment.NewLine);
455455

456456
builder.AppendLine($"wamAccount.AccountId: {string.IsNullOrEmpty(wamAccount.AccountId)}.");
@@ -461,7 +461,7 @@ private static void ToLogMessage(
461461
logger.InfoPii(messageWithPii, builder.ToString());
462462
}
463463

464-
logger.Error($"[WamBroker] WAM Account properties are missing. Cannot convert to MSAL Accounts.");
464+
logger.Error($"[RuntimeBroker] WAM Account properties are missing. Cannot convert to MSAL Accounts.");
465465
}
466466
}
467467
}

0 commit comments

Comments
 (0)