Skip to content

Commit

Permalink
AAD: refactor (#2288)
Browse files Browse the repository at this point in the history
* AAD: refactor

* change property to internal
  • Loading branch information
TimothyMothra authored May 28, 2021
1 parent 353d122 commit 9ecce67
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
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<string>
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<bool>
Microsoft.ApplicationInsights.Channel.InMemoryChannel.FlushAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
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<string>
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<bool>
Microsoft.ApplicationInsights.Channel.InMemoryChannel.FlushAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
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<string>
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<bool>
Microsoft.ApplicationInsights.Channel.InMemoryChannel.FlushAsync(System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task<bool>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// 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).
/// </summary>
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.

/// <summary>
/// Get scopes for Azure Monitor as an array.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,28 @@
using System.Threading;
using System.Threading.Tasks;

internal interface ICredentialEnvelope
/// <summary>
/// This interface defines a class that can interact with Azure.Core.TokenCredential.
/// </summary>
public abstract class CredentialEnvelope
{
/// <summary>
/// Gets the TokenCredential instance held by this class.
/// </summary>
object Credential { get; }
internal abstract object Credential { get; }

/// <summary>
/// Gets an Azure.Core.AccessToken.
/// </summary>
/// <param name="cancellationToken">The System.Threading.CancellationToken to use.</param>
/// <returns>A valid Azure.Core.AccessToken.</returns>
string GetToken(CancellationToken cancellationToken = default);
public abstract string GetToken(CancellationToken cancellationToken = default);

/// <summary>
/// Gets an Azure.Core.AccessToken.
/// </summary>
/// <param name="cancellationToken">The System.Threading.CancellationToken to use.</param>
/// <returns>A valid Azure.Core.AccessToken.</returns>
Task<string> GetTokenAsync(CancellationToken cancellationToken = default);
public abstract Task<string> GetTokenAsync(CancellationToken cancellationToken = default);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/// Our SDK currently targets net452, net46, and netstandard2.0.
/// Azure.Core.TokenCredential is only available for netstandard2.0.
/// </remarks>
internal class ReflectionCredentialEnvelope : ICredentialEnvelope
internal class ReflectionCredentialEnvelope : CredentialEnvelope
{
private readonly object tokenCredential;
private readonly object tokenRequestContext;
Expand All @@ -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
{
Expand All @@ -41,14 +41,14 @@ public ReflectionCredentialEnvelope(object tokenCredential)
/// <summary>
/// Gets the TokenCredential instance held by this class.
/// </summary>
public object Credential => this.tokenCredential;
internal override object Credential => this.tokenCredential;

/// <summary>
/// Gets an Azure.Core.AccessToken.
/// </summary>
/// <param name="cancellationToken">The System.Threading.CancellationToken to use.</param>
/// <returns>A valid Azure.Core.AccessToken.</returns>
public string GetToken(CancellationToken cancellationToken = default)
public override string GetToken(CancellationToken cancellationToken = default)
{
SdkInternalOperationsMonitor.Enter();
try
Expand All @@ -71,7 +71,7 @@ public string GetToken(CancellationToken cancellationToken = default)
/// </summary>
/// <param name="cancellationToken">The System.Threading.CancellationToken to use.</param>
/// <returns>A valid Azure.Core.AccessToken.</returns>
public async Task<string> GetTokenAsync(CancellationToken cancellationToken = default)
public override async Task<string> GetTokenAsync(CancellationToken cancellationToken = default)
{
SdkInternalOperationsMonitor.Enter();
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public string ConnectionString
/// <summary>
/// Gets an envelope for Azure.Core.TokenCredential which provides an AAD Authenticated token.
/// </summary>
internal ICredentialEnvelope CredentialEnvelope { get; private set; }
public CredentialEnvelope CredentialEnvelope { get; private set; }

/// <summary>
/// Gets or sets the chain of processors.
Expand Down

0 comments on commit 9ecce67

Please sign in to comment.