1// Copyright (c) Microsoft. All rights reserved.2// Licensed under the MIT license. See LICENSE file in the project root for full license information.34namespace Microsoft.Azure.ServiceBus.Primitives5{6 using System;7 using System.Threading.Tasks;8 using Azure.Services.AppAuthentication;910 /// <summary>11 /// Represents the Azure Active Directory token provider for Azure Managed Identity integration.12 /// </summary>13 public class ManagedIdentityTokenProvider : TokenProvider14 {15 private readonly AzureServiceTokenProvider azureServiceTokenProvider;1617 /// <summary>Initializes new instance of <see cref="ManagedIdentityTokenProvider"/> class with default <see cref18 public ManagedIdentityTokenProvider() : this(new AzureServiceTokenProvider()){}1920 /// <summary>Initializes new instance of <see cref="ManagedIdentityTokenProvider"/> class with <see cref="AzureS21 /// <remarks>Call that constructore to set <see cref="AzureServiceTokenProvider"/> with required Managed Identit22 public ManagedIdentityTokenProvider(AzureServiceTokenProvider azureServiceTokenProvider)23 {24 this.azureServiceTokenProvider = azureServiceTokenProvider;25 }2627 /// <summary>28 /// Gets a <see cref="SecurityToken"/> for the given audience and duration.29 /// </summary>30 /// <param name="appliesTo">The URI which the access token applies to</param>31 /// <param name="timeout">The time span that specifies the timeout value for the message that gets the security 32 /// <returns><see cref="SecurityToken"/></returns>33 public async override Task<SecurityToken> GetTokenAsync(string appliesTo, TimeSpan timeout)34 {35 string accessToken = await azureServiceTokenProvider.GetAccessTokenAsync(Constants.AadServiceBusAudience).Co36 return new JsonSecurityToken(accessToken, appliesTo);37 }38 }39}ncG1vNJzZmiZqqq%2Fpr%2FDpJirrJmbrqTA0meZpaeSY7CwvsRnrqKmlKTEtHrNnqtomaqqv6Z50p2iZp6fp3qvsdNoeqiclVp%2FcY%2FOr5yrmZeafI61wqumrKeWqXuCxtSrnGeLlafDqq%2FEe6ysl32Wu6KzxJ2AnZ2eqba1xbOoop6mgKe8t7XDnqlnoKSiuQ%3D%3D