Skip to content

Commit

Permalink
Modified cache logging to be more clear (#3072)
Browse files Browse the repository at this point in the history
* Modified cache logging to be more clear

* Refactoring

Co-authored-by: trwalke <trwalke@microsoft.com>
  • Loading branch information
trwalke and trwalke committed Dec 15, 2021
1 parent c240dad commit 191d0dc
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,19 +361,23 @@ private void LogReturnedToken(AuthenticationResult result)
if (result.AccessToken != null &&
AuthenticationRequestParameters.RequestContext.Logger.IsLoggingEnabled(LogLevel.Info))
{
int appHashCode = AuthenticationRequestParameters.AppConfig.GetHashCode();
string scopes = string.Join(" ", result.Scopes);
Uri canonicalAuthority = new Uri(AuthenticationRequestParameters.AuthorityInfo.CanonicalAuthority);
AuthenticationRequestParameters.RequestContext.Logger.InfoPii(
$"Fetched access token from host {canonicalAuthority.Host}. Endpoint {canonicalAuthority}. ",
$"Fetched access token from host {canonicalAuthority.Host}. ");


AuthenticationRequestParameters.RequestContext.Logger.Info("\n\t=== Token Acquisition finished successfully:");
AuthenticationRequestParameters.RequestContext.Logger.InfoPii(
$" AT expiration time: {result.ExpiresOn}, scopes {scopes} " +
$"source {result.AuthenticationResultMetadata.TokenSource} from {canonicalAuthority} appHashCode {appHashCode}",
$" AT expiration time: {result.ExpiresOn}, scopes {scopes} " +
$"source {result.AuthenticationResultMetadata.TokenSource} from {canonicalAuthority.Host} appHashCode {appHashCode}");
$" AT expiration time: {result.ExpiresOn}, scopes {scopes}" +
$"source {result.AuthenticationResultMetadata.TokenSource}",
$" AT expiration time: {result.ExpiresOn}, scopes {scopes}" +
$"source {result.AuthenticationResultMetadata.TokenSource}");

if (result.AuthenticationResultMetadata.TokenSource != TokenSource.Cache)
{
Uri canonicalAuthority = new Uri(AuthenticationRequestParameters.AuthorityInfo.CanonicalAuthority);

AuthenticationRequestParameters.RequestContext.Logger.InfoPii(
$"Fetched access token from host {canonicalAuthority.Host}. Endpoint {canonicalAuthority}. ",
$"Fetched access token from host {canonicalAuthority.Host}. ");
}
}
}

Expand Down

0 comments on commit 191d0dc

Please sign in to comment.