File tree Expand file tree Collapse file tree 4 files changed +9
-26
lines changed
Test/Microsoft.ApplicationInsights.Test/Microsoft.ApplicationInsights.Tests/Extensibility/Implementation/Authentication
src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication Expand file tree Collapse file tree 4 files changed +9
-26
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,8 @@ namespace Microsoft.ApplicationInsights.TestFramework.Extensibility.Implementati
29
29
[ TestCategory ( "AAD" ) ]
30
30
public class ReflectionCredentialEnvelopeTests
31
31
{
32
+ private readonly string [ ] defaultScope = new string [ ] { "https://monitor.azure.com/.default" } ;
33
+
32
34
[ TestMethod ]
33
35
public void VerifyCanIdentifyValidClass ( )
34
36
{
@@ -130,7 +132,7 @@ public async Task VerifyGetTokenAsync_UsingDynamicTypes()
130
132
[ TestMethod ]
131
133
public void VerifyGetToken_ReturnsValidToken ( )
132
134
{
133
- var requestContext = new TokenRequestContext ( scopes : AuthConstants . GetScopes ( ) ) ;
135
+ var requestContext = new TokenRequestContext ( scopes : defaultScope ) ;
134
136
var mockCredential = new MockCredential ( ) ;
135
137
var tokenFromCredential = mockCredential . GetToken ( requestContext , CancellationToken . None ) ;
136
138
@@ -147,7 +149,7 @@ public void VerifyGetToken_ReturnsValidToken()
147
149
[ TestMethod ]
148
150
public async Task VerifyGetTokenAsync_ReturnsValidToken ( )
149
151
{
150
- var requestContext = new TokenRequestContext ( scopes : AuthConstants . GetScopes ( ) ) ;
152
+ var requestContext = new TokenRequestContext ( scopes : defaultScope ) ;
151
153
var mockCredential = new MockCredential ( ) ;
152
154
var tokenFromCredential = await mockCredential . GetTokenAsync ( requestContext , CancellationToken . None ) ;
153
155
Original file line number Diff line number Diff line change @@ -5,18 +5,5 @@ internal static class AuthConstants
5
5
public const string AuthorizationHeaderName = "Authorization" ;
6
6
7
7
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 } ;
21
8
}
22
9
}
Original file line number Diff line number Diff line change @@ -82,20 +82,13 @@ internal string[] Scopes
82
82
{
83
83
get
84
84
{
85
- if ( string . IsNullOrEmpty ( this . Audience ) )
85
+ var normalizedScope = this . Audience ;
86
+ if ( ! normalizedScope . EndsWith ( ".default" ) )
86
87
{
87
- return new string [ ] { "https://monitor.azure.com/. default" } ;
88
+ normalizedScope += ". default";
88
89
}
89
- else
90
- {
91
- var normalizedScope = this . Audience ;
92
- if ( ! normalizedScope . EndsWith ( "/.default" ) )
93
- {
94
- normalizedScope += ".default" ;
95
- }
96
90
97
- return new string [ ] { normalizedScope } ;
98
- }
91
+ return new string [ ] { normalizedScope } ;
99
92
}
100
93
}
101
94
Original file line number Diff line number Diff line change 1
1
# Changelog
2
2
3
3
## VNext
4
+ - Parse AADAudience from ConnectionString to build scope for token requests
4
5
5
6
## Version 2.23.0
6
7
- no changes since beta.
You can’t perform that action at this time.
0 commit comments