diff --git a/libraries/Microsoft.Bot.Connector/Authentication/ManagedIdentityAuthenticator.cs b/libraries/Microsoft.Bot.Connector/Authentication/ManagedIdentityAuthenticator.cs index b16078809a..d19bf25a20 100644 --- a/libraries/Microsoft.Bot.Connector/Authentication/ManagedIdentityAuthenticator.cs +++ b/libraries/Microsoft.Bot.Connector/Authentication/ManagedIdentityAuthenticator.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Identity.Client; +using Microsoft.Identity.Client.AppConfig; namespace Microsoft.Bot.Connector.Authentication { @@ -16,10 +17,9 @@ namespace Microsoft.Bot.Connector.Authentication /// public class ManagedIdentityAuthenticator : IAuthenticator { - private readonly string _appId; private readonly string _resource; private readonly ILogger _logger; - private readonly IConfidentialClientApplication _clientApplication; + private readonly IManagedIdentityApplication _clientApplication; /// /// Initializes a new instance of the class. @@ -54,7 +54,6 @@ public ManagedIdentityAuthenticator(string appId, string resource, HttpClient cu throw new ArgumentNullException(nameof(resource)); } - _appId = appId; _resource = resource; _logger = logger ?? NullLogger.Instance; _clientApplication = CreateClientApplication(appId, customHttpClient); @@ -77,10 +76,8 @@ public async Task GetTokenAsync(bool forceRefresh = false) private async Task AcquireTokenAsync(bool forceRefresh) { - var scopes = new string[] { $"{_resource}/.default" }; var authResult = await _clientApplication - .AcquireTokenForClient(scopes) - .WithManagedIdentity(_appId) + .AcquireTokenForManagedIdentity(_resource) .WithForceRefresh(forceRefresh) .ExecuteAsync() .ConfigureAwait(false); @@ -100,10 +97,9 @@ private RetryParams HandleTokenProviderException(Exception e, int retryCount) : RetryParams.DefaultBackOff(retryCount); } - private IConfidentialClientApplication CreateClientApplication(string appId, HttpClient customHttpClient = null) + private IManagedIdentityApplication CreateClientApplication(string appId, HttpClient customHttpClient = null) { - var clientBuilder = ConfidentialClientApplicationBuilder.Create(appId) - .WithExperimentalFeatures(); + var clientBuilder = ManagedIdentityApplicationBuilder.Create(ManagedIdentityId.WithUserAssignedClientId(appId)); if (customHttpClient != null) { diff --git a/libraries/Microsoft.Bot.Connector/Microsoft.Bot.Connector.csproj b/libraries/Microsoft.Bot.Connector/Microsoft.Bot.Connector.csproj index 244dea2297..ffe70e6c9c 100644 --- a/libraries/Microsoft.Bot.Connector/Microsoft.Bot.Connector.csproj +++ b/libraries/Microsoft.Bot.Connector/Microsoft.Bot.Connector.csproj @@ -29,7 +29,7 @@ - +