Skip to content

Commit af7dcaa

Browse files
committed
Minor tweaks/fixups
- Added line to CHANGELOG describing update - Removed audience/scope values from AuthConstants as they are no longer used. Modified tests accordingly.
1 parent 9567a52 commit af7dcaa

File tree

4 files changed

+9
-26
lines changed

4 files changed

+9
-26
lines changed

BASE/Test/Microsoft.ApplicationInsights.Test/Microsoft.ApplicationInsights.Tests/Extensibility/Implementation/Authentication/ReflectionCredentialEnvelopeTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ namespace Microsoft.ApplicationInsights.TestFramework.Extensibility.Implementati
2929
[TestCategory("AAD")]
3030
public class ReflectionCredentialEnvelopeTests
3131
{
32+
private readonly string[] defaultScope = new string[] { "https://monitor.azure.com/.default" };
33+
3234
[TestMethod]
3335
public void VerifyCanIdentifyValidClass()
3436
{
@@ -130,7 +132,7 @@ public async Task VerifyGetTokenAsync_UsingDynamicTypes()
130132
[TestMethod]
131133
public void VerifyGetToken_ReturnsValidToken()
132134
{
133-
var requestContext = new TokenRequestContext(scopes: AuthConstants.GetScopes());
135+
var requestContext = new TokenRequestContext(scopes: defaultScope);
134136
var mockCredential = new MockCredential();
135137
var tokenFromCredential = mockCredential.GetToken(requestContext, CancellationToken.None);
136138

@@ -147,7 +149,7 @@ public void VerifyGetToken_ReturnsValidToken()
147149
[TestMethod]
148150
public async Task VerifyGetTokenAsync_ReturnsValidToken()
149151
{
150-
var requestContext = new TokenRequestContext(scopes: AuthConstants.GetScopes());
152+
var requestContext = new TokenRequestContext(scopes: defaultScope);
151153
var mockCredential = new MockCredential();
152154
var tokenFromCredential = await mockCredential.GetTokenAsync(requestContext, CancellationToken.None);
153155

BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/AuthConstants.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,5 @@ internal static class AuthConstants
55
public const string AuthorizationHeaderName = "Authorization";
66

77
public const string AuthorizationTokenPrefix = "Bearer ";
8-
9-
/// <summary>
10-
/// Source:
11-
/// (https://docs.microsoft.com/azure/active-directory/develop/msal-acquire-cache-tokens#scopes-when-acquiring-tokens).
12-
/// (https://docs.microsoft.com/azure/active-directory/develop/v2-permissions-and-consent#the-default-scope).
13-
/// </summary>
14-
private const string AzureMonitorScope = "https://monitor.azure.com//.default";
15-
16-
/// <summary>
17-
/// Get scopes for Azure Monitor as an array.
18-
/// </summary>
19-
/// <returns>An array of scopes.</returns>
20-
public static string[] GetScopes() => new string[] { AzureMonitorScope };
218
}
229
}

BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/ReflectionCredentialEnvelope.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,13 @@ internal string[] Scopes
8282
{
8383
get
8484
{
85-
if (string.IsNullOrEmpty(this.Audience))
85+
var normalizedScope = this.Audience;
86+
if (!normalizedScope.EndsWith(".default"))
8687
{
87-
return new string[] { "https://monitor.azure.com/.default" };
88+
normalizedScope += ".default";
8889
}
89-
else
90-
{
91-
var normalizedScope = this.Audience;
92-
if (!normalizedScope.EndsWith("/.default"))
93-
{
94-
normalizedScope += ".default";
95-
}
9690

97-
return new string[] { normalizedScope };
98-
}
91+
return new string[] { normalizedScope };
9992
}
10093
}
10194

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## VNext
4+
- Parse AADAudience from ConnectionString to build scope for token requests
45

56
## Version 2.23.0
67
- no changes since beta.

0 commit comments

Comments
 (0)