Skip to content

Commit 2ad7d8d

Browse files
trwalketrwalkegladjohn
authored
Updating extension telemetry (#4996)
* Updating extension telemetry * Refactroing Removing TokenType and replacing the values with string * Updating PR to revert new histogram logic. * TODO * Refactoring. Addressing Feedback * Apply suggestions from code review Co-authored-by: Gladwin Johnson <[email protected]> * Addressing PR Feedback * Update * Resolving test issues * Removing External * update * Updating WAM header * Resolving WAM test issues * Fixing test --------- Co-authored-by: trwalke <[email protected]> Co-authored-by: Gladwin Johnson <[email protected]>
1 parent b54af18 commit 2ad7d8d

30 files changed

+138
-108
lines changed

src/client/Microsoft.Identity.Client.Broker/WamAdapters.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,11 @@ private static MsalTokenResponse ParseRuntimeResponse(
362362
Scope = authResult.GrantedScopes,
363363
ExpiresIn = (long)(DateTime.SpecifyKind(authResult.ExpiresOn, DateTimeKind.Utc) - DateTimeOffset.UtcNow).TotalSeconds,
364364
ClientInfo = authResult.Account.ClientInfo,
365-
TokenType = authResult.IsPopAuthorization ? Constants.PoPAuthHeaderPrefix: authenticationRequestParameters.RequestContext.ApiEvent.TokenType.ToString(),
365+
TokenType = authResult.IsPopAuthorization ?
366+
Constants.PoPAuthHeaderPrefix :
367+
(authenticationRequestParameters.AuthenticationScheme.AccessTokenType == "ssh-cert" ?
368+
Constants.SshCertAuthHeaderPrefix :
369+
authenticationRequestParameters.AuthenticationScheme.AuthorizationHeaderPrefix),
366370
WamAccountId = authResult.Account.AccountId,
367371
TokenSource = TokenSource.Broker
368372
};

src/client/Microsoft.Identity.Client/AuthScheme/Bearer/BearerAuthenticationOperation.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Collections.Generic;
55
using Microsoft.Identity.Client.Cache.Items;
6+
using Microsoft.Identity.Client.Internal;
67
using Microsoft.Identity.Client.Utils;
78

89
namespace Microsoft.Identity.Client.AuthScheme.Bearer
@@ -11,7 +12,7 @@ internal class BearerAuthenticationOperation : IAuthenticationOperation
1112
{
1213
internal const string BearerTokenType = "bearer";
1314

14-
public int TelemetryTokenType => (int)TokenType.Bearer;
15+
public int TelemetryTokenType => TelemetryTokenTypeConstants.Bearer;
1516

1617
public string AuthorizationHeaderPrefix => "Bearer";
1718

src/client/Microsoft.Identity.Client/AuthScheme/IAuthenticationOperation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public interface IAuthenticationOperation
3838
string AuthorizationHeaderPrefix { get; }
3939

4040
/// <summary>
41-
/// Extra parameters that are added to the request to the /token endpoint.
41+
/// Extra parameters that are added to the request to the /token endpoint.
4242
/// </summary>
4343
/// <returns>Name and values of params</returns>
4444
IReadOnlyDictionary<string, string> GetTokenRequestParams();

src/client/Microsoft.Identity.Client/AuthScheme/PoP/PopAuthenticationOperation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public PopAuthenticationOperation(PoPAuthenticationConfiguration popAuthenticati
4848
KeyId = Base64UrlHelpers.Encode(keyThumbprint);
4949
}
5050

51-
public int TelemetryTokenType => (int)TokenType.Pop;
51+
public int TelemetryTokenType => TelemetryTokenTypeConstants.Pop;
5252

5353
public string AuthorizationHeaderPrefix => Constants.PoPAuthHeaderPrefix;
5454

src/client/Microsoft.Identity.Client/AuthScheme/PoP/PopBrokerAuthenticationOperation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Microsoft.Identity.Client.AuthScheme.PoP
1717
//This is because tokens are cached in the broker instead so MSAL will rely on the broker's cache for silent requests.
1818
internal class PopBrokerAuthenticationOperation : IAuthenticationOperation
1919
{
20-
public int TelemetryTokenType => (int)TokenType.Pop;
20+
public int TelemetryTokenType => TelemetryTokenTypeConstants.Pop;
2121

2222
public string AuthorizationHeaderPrefix => Constants.PoPAuthHeaderPrefix;
2323

src/client/Microsoft.Identity.Client/AuthScheme/SSHCertificates/SSHCertAuthenticationOperation.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using Microsoft.Identity.Client.Cache.Items;
7+
using Microsoft.Identity.Client.Internal;
78
using Microsoft.Identity.Client.OAuth2;
89

910
namespace Microsoft.Identity.Client.AuthScheme.SSHCertificates
@@ -29,7 +30,7 @@ public SSHCertAuthenticationOperation(string keyId, string jwk)
2930
_jwk = jwk;
3031
}
3132

32-
public int TelemetryTokenType => (int)TokenType.SshCert;
33+
public int TelemetryTokenType => TelemetryTokenTypeConstants.SshCert;
3334

3435
public string AuthorizationHeaderPrefix =>
3536
throw new MsalClientException(

src/client/Microsoft.Identity.Client/AuthScheme/TokenType.cs

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/client/Microsoft.Identity.Client/AuthenticationResult.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,8 @@ internal AuthenticationResult(
196196
authenticationScheme.FormatResult(this);
197197
});
198198

199-
if (authenticationScheme.TelemetryTokenType == 5)
200-
{
201-
AuthenticationResultMetadata.DurationCreatingExtendedTokenInUs = measuredResultDuration.Microseconds;
202-
}
199+
AuthenticationResultMetadata.DurationCreatingExtendedTokenInUs = measuredResultDuration.Microseconds;
200+
AuthenticationResultMetadata.TelemetryTokenType = authenticationScheme.TelemetryTokenType;
203201
}
204202

205203
//Default constructor for testing

src/client/Microsoft.Identity.Client/AuthenticationResultMetadata.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ public AuthenticationResultMetadata(TokenSource tokenSource)
7777
/// </summary>
7878
public RegionDetails RegionDetails { get; set; }
7979

80+
/// <summary>
81+
/// Represents the token type used for client telemetry only.
82+
/// It is separate from the other token types as it is set locally rather than coming from the server.
83+
/// </summary>
84+
public int TelemetryTokenType { get; set; }
85+
8086
/// <summary>
8187
/// Time, in microseconds, spent in the token creation of the extended token.
8288
/// </summary>

src/client/Microsoft.Identity.Client/Extensibility/ExternalBoundTokenScheme.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using Microsoft.Identity.Client.AuthScheme;
66
using Microsoft.Identity.Client.Cache.Items;
7+
using Microsoft.Identity.Client.Internal;
78
using Microsoft.Identity.Client.Utils;
89

910
namespace Microsoft.Identity.Client.Extensibility
@@ -19,7 +20,7 @@ public ExternalBoundTokenScheme(string keyId, string expectedTokenTypeFromEsts =
1920
_tokenType = expectedTokenTypeFromEsts;
2021
}
2122

22-
public int TelemetryTokenType => (int)TokenType.External;
23+
public int TelemetryTokenType => TelemetryTokenTypeConstants.AtPop;
2324

2425
public string AuthorizationHeaderPrefix => _tokenType;
2526

0 commit comments

Comments
 (0)