Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ExtraQP to inject telemetry SDK ID #2973

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
using System.Reflection;
using System.Text.RegularExpressions;

namespace Microsoft.Identity.Web
namespace Microsoft.Identity.Web.Diagnostics
{
internal static class IdHelper
{
private const string IDWebSku = "IDWeb.";

private static readonly Lazy<string> s_idWebVersion = new Lazy<string>(
() =>
{
Expand All @@ -34,9 +36,14 @@ internal static class IdHelper
return version[1];
});

public static string GetIdWebVersion()
{
return s_idWebVersion.Value;
}

public static string CreateTelemetryInfo()
{
return string.Format(CultureInfo.InvariantCulture, Constants.IDWebSku + s_idWebVersion.Value);
return string.Format(CultureInfo.InvariantCulture, IDWebSku + GetIdWebVersion());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Microsoft.Identity.Web.Diagnostics.IdHelper
static Microsoft.Identity.Web.Diagnostics.IdHelper.CreateTelemetryInfo() -> string!
static Microsoft.Identity.Web.Diagnostics.IdHelper.GetIdWebVersion() -> string!
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Microsoft.Identity.Web.Diagnostics.IdHelper
static Microsoft.Identity.Web.Diagnostics.IdHelper.CreateTelemetryInfo() -> string!
static Microsoft.Identity.Web.Diagnostics.IdHelper.GetIdWebVersion() -> string!
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Microsoft.Identity.Web.Diagnostics.IdHelper
static Microsoft.Identity.Web.Diagnostics.IdHelper.CreateTelemetryInfo() -> string!
static Microsoft.Identity.Web.Diagnostics.IdHelper.GetIdWebVersion() -> string!
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Microsoft.Identity.Web.Diagnostics.IdHelper
static Microsoft.Identity.Web.Diagnostics.IdHelper.CreateTelemetryInfo() -> string!
static Microsoft.Identity.Web.Diagnostics.IdHelper.GetIdWebVersion() -> string!
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Microsoft.Identity.Web.Diagnostics.IdHelper
static Microsoft.Identity.Web.Diagnostics.IdHelper.CreateTelemetryInfo() -> string!
static Microsoft.Identity.Web.Diagnostics.IdHelper.GetIdWebVersion() -> string!
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Microsoft.Identity.Web.Diagnostics.IdHelper
static Microsoft.Identity.Web.Diagnostics.IdHelper.CreateTelemetryInfo() -> string!
static Microsoft.Identity.Web.Diagnostics.IdHelper.GetIdWebVersion() -> string!
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Microsoft.Identity.Web.Diagnostics.IdHelper
static Microsoft.Identity.Web.Diagnostics.IdHelper.CreateTelemetryInfo() -> string!
static Microsoft.Identity.Web.Diagnostics.IdHelper.GetIdWebVersion() -> string!
643 changes: 334 additions & 309 deletions src/Microsoft.Identity.Web.DownstreamApi/DownstreamApi.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
bn
static Microsoft.Identity.Web.DownstreamApi.CallerSDKDetails.get -> System.Collections.Generic.Dictionary<string!, string!>!
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
static Microsoft.Identity.Web.DownstreamApi.CallerSDKDetails.get -> System.Collections.Generic.Dictionary<string!, string!>!
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
static Microsoft.Identity.Web.DownstreamApi.CallerSDKDetails.get -> System.Collections.Generic.Dictionary<string!, string!>!
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
static Microsoft.Identity.Web.DownstreamApi.CallerSDKDetails.get -> System.Collections.Generic.Dictionary<string!, string!>!
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
static Microsoft.Identity.Web.DownstreamApi.CallerSDKDetails.get -> System.Collections.Generic.Dictionary<string!, string!>!
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
static Microsoft.Identity.Web.DownstreamApi.CallerSDKDetails.get -> System.Collections.Generic.Dictionary<string!, string!>!
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
static Microsoft.Identity.Web.DownstreamApi.CallerSDKDetails.get -> System.Collections.Generic.Dictionary<string!, string!>!
1 change: 1 addition & 0 deletions src/Microsoft.Identity.Web.OWIN/AppBuilderExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Microsoft.Owin.Security.Jwt;
using Microsoft.Owin.Security.OAuth;
using Microsoft.Owin.Security.OpenIdConnect;
using Microsoft.Identity.Web.Diagnostics;
using Owin;

namespace Microsoft.Identity.Web
Expand Down
1 change: 0 additions & 1 deletion src/Microsoft.Identity.Web.TokenAcquisition/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ public static class Constants

// Telemetry headers
internal const string TelemetryHeaderKey = "x-client-brkrver";
internal const string IDWebSku = "IDWeb.";

// Authorize for scopes attributes
internal const string XReturnUrl = "x-ReturnUrl";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Net.Http;
using Microsoft.Identity.Client;
using Microsoft.Identity.Web.Diagnostics;

namespace Microsoft.Identity.Web
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using System.Linq;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Identity.Web.Diagnostics;

namespace Microsoft.Identity.Web
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,51 @@ public async Task UpdateRequestAsync_WithContent_AddsContentToRequestAsync()
// Arrange
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "https://example.com");
var content = new StringContent("test content");
var options = new DownstreamApiOptions();

// Act
await _input.UpdateRequestAsync(httpRequestMessage, content, new DownstreamApiOptions(), false, null, CancellationToken.None);
await _input.UpdateRequestAsync(httpRequestMessage, content, options, false, null, CancellationToken.None);

// Assert
Assert.Equal(content, httpRequestMessage.Content);
Assert.Equal("application/json", httpRequestMessage.Headers.Accept.Single().MediaType);
Assert.Equal("text/plain", httpRequestMessage.Content?.Headers.ContentType?.MediaType);
Assert.Equal(options.AcquireTokenOptions.ExtraQueryParameters, DownstreamApi.CallerSDKDetails);
}


[Fact]
public async Task UpdateRequestAsync_AddsToExtraQP()
{
// Arrange
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "https://example.com");
var content = new StringContent("test content");
var options = new DownstreamApiOptions() {
AcquireTokenOptions = new AcquireTokenOptions() {
ExtraQueryParameters = new Dictionary<string, string>()
{
{ "n1", "v1" },
{ "n2", "v2" },
{ "caller-sdk-id", "bogus" } // value will be overwritten by the SDK
}
} };

// Act
await _input.UpdateRequestAsync(httpRequestMessage, content, options, false, null, CancellationToken.None);

// Assert
Assert.Equal(content, httpRequestMessage.Content);
Assert.Equal("application/json", httpRequestMessage.Headers.Accept.Single().MediaType);
Assert.Equal("text/plain", httpRequestMessage.Content?.Headers.ContentType?.MediaType);
Assert.Equal("v1", options.AcquireTokenOptions.ExtraQueryParameters["n1"]);
Assert.Equal("v2", options.AcquireTokenOptions.ExtraQueryParameters["n2"]);
Assert.Equal(
DownstreamApi.CallerSDKDetails["caller-sdk-id"],
options.AcquireTokenOptions.ExtraQueryParameters["caller-sdk-id"] );
Assert.Equal(
DownstreamApi.CallerSDKDetails["caller-sdk-ver"],
options.AcquireTokenOptions.ExtraQueryParameters["caller-sdk-ver"]);

}

[Theory]
Expand All @@ -83,6 +120,7 @@ public async Task UpdateRequestAsync_WithScopes_AddsAuthorizationHeaderToRequest
Assert.Equal("ey", httpRequestMessage.Headers.Authorization?.Parameter);
Assert.Equal("Bearer", httpRequestMessage.Headers.Authorization?.Scheme);
Assert.Equal("application/json", httpRequestMessage.Headers.Accept.Single().MediaType);
Assert.Equal(options.AcquireTokenOptions.ExtraQueryParameters, DownstreamApi.CallerSDKDetails);
}

[Fact]
Expand Down
Loading