From 205337165fb3cd548d9c0a3ae6994a56aa00d972 Mon Sep 17 00:00:00 2001 From: Timothy Mothra Lee Date: Fri, 28 May 2021 10:37:12 -0700 Subject: [PATCH 1/2] AAD: refactor --- .../net452/PublicAPI.Unshipped.txt | 7 ++++++- .../net46/PublicAPI.Unshipped.txt | 7 ++++++- .../netstandard2.0/PublicAPI.Unshipped.txt | 7 ++++++- .../ReflectionCredentialEnvelopeTests.cs | 4 ++-- .../{CredentialConstants.cs => AuthConstants.cs} | 10 ++-------- ...ICredentialEnvelope.cs => CredentialEnvelope.cs} | 13 ++++++++----- .../Authentication/ReflectionCredentialEnvelope.cs | 10 +++++----- .../Extensibility/TelemetryConfiguration.cs | 2 +- 8 files changed, 36 insertions(+), 24 deletions(-) rename BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/{CredentialConstants.cs => AuthConstants.cs} (63%) rename BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/{ICredentialEnvelope.cs => CredentialEnvelope.cs} (65%) diff --git a/.publicApi/Microsoft.ApplicationInsights.dll/net452/PublicAPI.Unshipped.txt b/.publicApi/Microsoft.ApplicationInsights.dll/net452/PublicAPI.Unshipped.txt index 44ef0ab106..03ccefc0b5 100644 --- a/.publicApi/Microsoft.ApplicationInsights.dll/net452/PublicAPI.Unshipped.txt +++ b/.publicApi/Microsoft.ApplicationInsights.dll/net452/PublicAPI.Unshipped.txt @@ -1,5 +1,10 @@ +abstract Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope.Credential.get -> object +abstract Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope.GetToken(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> string +abstract Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope.GetTokenAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task +Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope +Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope.CredentialEnvelope() -> void +Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.CredentialEnvelope.get -> Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.SetAzureTokenCredential(object tokenCredential) -> void - Microsoft.ApplicationInsights.Channel.IAsyncFlushable Microsoft.ApplicationInsights.Channel.IAsyncFlushable.FlushAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task Microsoft.ApplicationInsights.Channel.InMemoryChannel.FlushAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task diff --git a/.publicApi/Microsoft.ApplicationInsights.dll/net46/PublicAPI.Unshipped.txt b/.publicApi/Microsoft.ApplicationInsights.dll/net46/PublicAPI.Unshipped.txt index 44ef0ab106..03ccefc0b5 100644 --- a/.publicApi/Microsoft.ApplicationInsights.dll/net46/PublicAPI.Unshipped.txt +++ b/.publicApi/Microsoft.ApplicationInsights.dll/net46/PublicAPI.Unshipped.txt @@ -1,5 +1,10 @@ +abstract Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope.Credential.get -> object +abstract Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope.GetToken(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> string +abstract Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope.GetTokenAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task +Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope +Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope.CredentialEnvelope() -> void +Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.CredentialEnvelope.get -> Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.SetAzureTokenCredential(object tokenCredential) -> void - Microsoft.ApplicationInsights.Channel.IAsyncFlushable Microsoft.ApplicationInsights.Channel.IAsyncFlushable.FlushAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task Microsoft.ApplicationInsights.Channel.InMemoryChannel.FlushAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task diff --git a/.publicApi/Microsoft.ApplicationInsights.dll/netstandard2.0/PublicAPI.Unshipped.txt b/.publicApi/Microsoft.ApplicationInsights.dll/netstandard2.0/PublicAPI.Unshipped.txt index 44ef0ab106..03ccefc0b5 100644 --- a/.publicApi/Microsoft.ApplicationInsights.dll/netstandard2.0/PublicAPI.Unshipped.txt +++ b/.publicApi/Microsoft.ApplicationInsights.dll/netstandard2.0/PublicAPI.Unshipped.txt @@ -1,5 +1,10 @@ +abstract Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope.Credential.get -> object +abstract Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope.GetToken(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> string +abstract Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope.GetTokenAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task +Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope +Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope.CredentialEnvelope() -> void +Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.CredentialEnvelope.get -> Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.SetAzureTokenCredential(object tokenCredential) -> void - Microsoft.ApplicationInsights.Channel.IAsyncFlushable Microsoft.ApplicationInsights.Channel.IAsyncFlushable.FlushAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task Microsoft.ApplicationInsights.Channel.InMemoryChannel.FlushAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task diff --git a/BASE/Test/Microsoft.ApplicationInsights.Test/Microsoft.ApplicationInsights.Tests/Extensibility/Implementation/Authentication/ReflectionCredentialEnvelopeTests.cs b/BASE/Test/Microsoft.ApplicationInsights.Test/Microsoft.ApplicationInsights.Tests/Extensibility/Implementation/Authentication/ReflectionCredentialEnvelopeTests.cs index 75535b7289..c6cf0dcc70 100644 --- a/BASE/Test/Microsoft.ApplicationInsights.Test/Microsoft.ApplicationInsights.Tests/Extensibility/Implementation/Authentication/ReflectionCredentialEnvelopeTests.cs +++ b/BASE/Test/Microsoft.ApplicationInsights.Test/Microsoft.ApplicationInsights.Tests/Extensibility/Implementation/Authentication/ReflectionCredentialEnvelopeTests.cs @@ -118,7 +118,7 @@ public async Task VerifyGetTokenAsync_UsingDynamicTypes() [TestMethod] public void VerifyGetToken_ReturnsValidToken() { - var requestContext = new TokenRequestContext(scopes: CredentialConstants.GetScopes()); + var requestContext = new TokenRequestContext(scopes: AuthConstants.GetScopes()); var mockCredential = new MockCredential(); var tokenUsingTypes = mockCredential.GetToken(requestContext, CancellationToken.None); @@ -134,7 +134,7 @@ public void VerifyGetToken_ReturnsValidToken() [TestMethod] public async Task VerifyGetTokenAsync_ReturnsValidToken() { - var requestContext = new TokenRequestContext(scopes: CredentialConstants.GetScopes()); + var requestContext = new TokenRequestContext(scopes: AuthConstants.GetScopes()); var mockCredential = new MockCredential(); var tokenUsingTypes = await mockCredential.GetTokenAsync(requestContext, CancellationToken.None); diff --git a/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/CredentialConstants.cs b/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/AuthConstants.cs similarity index 63% rename from BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/CredentialConstants.cs rename to BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/AuthConstants.cs index 3d6f253606..8a6da3ed86 100644 --- a/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/CredentialConstants.cs +++ b/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/AuthConstants.cs @@ -1,19 +1,13 @@ namespace Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication { - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - - internal static class CredentialConstants + internal static class AuthConstants { /// /// Source: /// (https://docs.microsoft.com/azure/active-directory/develop/msal-acquire-cache-tokens#scopes-when-acquiring-tokens). /// (https://docs.microsoft.com/azure/active-directory/develop/v2-permissions-and-consent#the-default-scope). /// - public const string AzureMonitorScope = "https://monitor.azure.com//.default"; // TODO: THIS SCOPE IS UNVERIFIED. WAITING FOR SERVICES TEAM TO PROVIDE AN INT ENVIRONMENT FOR E2E TESTING. + private const string AzureMonitorScope = "https://monitor.azure.com//.default"; // TODO: THIS SCOPE IS UNVERIFIED. WAITING FOR SERVICES TEAM TO PROVIDE AN INT ENVIRONMENT FOR E2E TESTING. /// /// Get scopes for Azure Monitor as an array. diff --git a/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/ICredentialEnvelope.cs b/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/CredentialEnvelope.cs similarity index 65% rename from BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/ICredentialEnvelope.cs rename to BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/CredentialEnvelope.cs index 7deca591c6..c4afb0b4d8 100644 --- a/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/ICredentialEnvelope.cs +++ b/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/CredentialEnvelope.cs @@ -3,25 +3,28 @@ using System.Threading; using System.Threading.Tasks; - internal interface ICredentialEnvelope + /// + /// This interface defines a class that can interact with Azure.Core.TokenCredential. + /// + public abstract class CredentialEnvelope { /// /// Gets the TokenCredential instance held by this class. /// - object Credential { get; } + public abstract object Credential { get; } /// /// Gets an Azure.Core.AccessToken. /// /// The System.Threading.CancellationToken to use. /// A valid Azure.Core.AccessToken. - string GetToken(CancellationToken cancellationToken = default); + public abstract string GetToken(CancellationToken cancellationToken = default); /// /// Gets an Azure.Core.AccessToken. /// /// The System.Threading.CancellationToken to use. /// A valid Azure.Core.AccessToken. - Task GetTokenAsync(CancellationToken cancellationToken = default); + public abstract Task GetTokenAsync(CancellationToken cancellationToken = default); } -} +} \ No newline at end of file diff --git a/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/ReflectionCredentialEnvelope.cs b/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/ReflectionCredentialEnvelope.cs index 6546b69d9a..d356ea0e81 100644 --- a/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/ReflectionCredentialEnvelope.cs +++ b/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/ReflectionCredentialEnvelope.cs @@ -15,7 +15,7 @@ /// Our SDK currently targets net452, net46, and netstandard2.0. /// Azure.Core.TokenCredential is only available for netstandard2.0. /// - internal class ReflectionCredentialEnvelope : ICredentialEnvelope + internal class ReflectionCredentialEnvelope : CredentialEnvelope { private readonly object tokenCredential; private readonly object tokenRequestContext; @@ -30,7 +30,7 @@ public ReflectionCredentialEnvelope(object tokenCredential) if (tokenCredential.GetType().IsSubclassOf(Type.GetType("Azure.Core.TokenCredential, Azure.Core"))) { - this.tokenRequestContext = AzureCore.MakeTokenRequestContext(scopes: CredentialConstants.GetScopes()); + this.tokenRequestContext = AzureCore.MakeTokenRequestContext(scopes: AuthConstants.GetScopes()); } else { @@ -41,14 +41,14 @@ public ReflectionCredentialEnvelope(object tokenCredential) /// /// Gets the TokenCredential instance held by this class. /// - public object Credential => this.tokenCredential; + public override object Credential => this.tokenCredential; /// /// Gets an Azure.Core.AccessToken. /// /// The System.Threading.CancellationToken to use. /// A valid Azure.Core.AccessToken. - public string GetToken(CancellationToken cancellationToken = default) + public override string GetToken(CancellationToken cancellationToken = default) { SdkInternalOperationsMonitor.Enter(); try @@ -71,7 +71,7 @@ public string GetToken(CancellationToken cancellationToken = default) /// /// The System.Threading.CancellationToken to use. /// A valid Azure.Core.AccessToken. - public async Task GetTokenAsync(CancellationToken cancellationToken = default) + public override async Task GetTokenAsync(CancellationToken cancellationToken = default) { SdkInternalOperationsMonitor.Enter(); try diff --git a/BASE/src/Microsoft.ApplicationInsights/Extensibility/TelemetryConfiguration.cs b/BASE/src/Microsoft.ApplicationInsights/Extensibility/TelemetryConfiguration.cs index 2db25dba0a..f8b0297828 100644 --- a/BASE/src/Microsoft.ApplicationInsights/Extensibility/TelemetryConfiguration.cs +++ b/BASE/src/Microsoft.ApplicationInsights/Extensibility/TelemetryConfiguration.cs @@ -338,7 +338,7 @@ public string ConnectionString /// /// Gets an envelope for Azure.Core.TokenCredential which provides an AAD Authenticated token. /// - internal ICredentialEnvelope CredentialEnvelope { get; private set; } + public CredentialEnvelope CredentialEnvelope { get; private set; } /// /// Gets or sets the chain of processors. From 4ecdfc40753dbc2c8e845fcd88b4ad26bc4e8a35 Mon Sep 17 00:00:00 2001 From: Timothy Mothra Lee Date: Fri, 28 May 2021 11:45:01 -0700 Subject: [PATCH 2/2] change property to internal --- .../net452/PublicAPI.Unshipped.txt | 1 - .../net46/PublicAPI.Unshipped.txt | 1 - .../netstandard2.0/PublicAPI.Unshipped.txt | 1 - .../Implementation/Authentication/CredentialEnvelope.cs | 2 +- .../Authentication/ReflectionCredentialEnvelope.cs | 2 +- 5 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.publicApi/Microsoft.ApplicationInsights.dll/net452/PublicAPI.Unshipped.txt b/.publicApi/Microsoft.ApplicationInsights.dll/net452/PublicAPI.Unshipped.txt index 03ccefc0b5..39e0d1c109 100644 --- a/.publicApi/Microsoft.ApplicationInsights.dll/net452/PublicAPI.Unshipped.txt +++ b/.publicApi/Microsoft.ApplicationInsights.dll/net452/PublicAPI.Unshipped.txt @@ -1,4 +1,3 @@ -abstract Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope.Credential.get -> object abstract Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope.GetToken(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> string abstract Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope.GetTokenAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope diff --git a/.publicApi/Microsoft.ApplicationInsights.dll/net46/PublicAPI.Unshipped.txt b/.publicApi/Microsoft.ApplicationInsights.dll/net46/PublicAPI.Unshipped.txt index 03ccefc0b5..39e0d1c109 100644 --- a/.publicApi/Microsoft.ApplicationInsights.dll/net46/PublicAPI.Unshipped.txt +++ b/.publicApi/Microsoft.ApplicationInsights.dll/net46/PublicAPI.Unshipped.txt @@ -1,4 +1,3 @@ -abstract Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope.Credential.get -> object abstract Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope.GetToken(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> string abstract Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope.GetTokenAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope diff --git a/.publicApi/Microsoft.ApplicationInsights.dll/netstandard2.0/PublicAPI.Unshipped.txt b/.publicApi/Microsoft.ApplicationInsights.dll/netstandard2.0/PublicAPI.Unshipped.txt index 03ccefc0b5..39e0d1c109 100644 --- a/.publicApi/Microsoft.ApplicationInsights.dll/netstandard2.0/PublicAPI.Unshipped.txt +++ b/.publicApi/Microsoft.ApplicationInsights.dll/netstandard2.0/PublicAPI.Unshipped.txt @@ -1,4 +1,3 @@ -abstract Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope.Credential.get -> object abstract Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope.GetToken(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> string abstract Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope.GetTokenAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task Microsoft.ApplicationInsights.Extensibility.Implementation.Authentication.CredentialEnvelope diff --git a/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/CredentialEnvelope.cs b/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/CredentialEnvelope.cs index c4afb0b4d8..ecc6931bf9 100644 --- a/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/CredentialEnvelope.cs +++ b/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/CredentialEnvelope.cs @@ -11,7 +11,7 @@ public abstract class CredentialEnvelope /// /// Gets the TokenCredential instance held by this class. /// - public abstract object Credential { get; } + internal abstract object Credential { get; } /// /// Gets an Azure.Core.AccessToken. diff --git a/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/ReflectionCredentialEnvelope.cs b/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/ReflectionCredentialEnvelope.cs index d356ea0e81..b441f952eb 100644 --- a/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/ReflectionCredentialEnvelope.cs +++ b/BASE/src/Microsoft.ApplicationInsights/Extensibility/Implementation/Authentication/ReflectionCredentialEnvelope.cs @@ -41,7 +41,7 @@ public ReflectionCredentialEnvelope(object tokenCredential) /// /// Gets the TokenCredential instance held by this class. /// - public override object Credential => this.tokenCredential; + internal override object Credential => this.tokenCredential; /// /// Gets an Azure.Core.AccessToken.