| | 1 | | // Copyright (c) Microsoft. All rights reserved. |
| | 2 | | // Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| | 3 | |
|
| | 4 | | namespace Microsoft.Azure.ServiceBus.Primitives |
| | 5 | | { |
| | 6 | | using System; |
| | 7 | | using System.Threading.Tasks; |
| | 8 | | using Azure.Services.AppAuthentication; |
| | 9 | |
|
| | 10 | | /// <summary> |
| | 11 | | /// Represents the Azure Active Directory token provider for Azure Managed Identity integration. |
| | 12 | | /// </summary> |
| | 13 | | public class ManagedIdentityTokenProvider : TokenProvider |
| | 14 | | { |
| | 15 | | private readonly AzureServiceTokenProvider azureServiceTokenProvider; |
| | 16 | |
|
| | 17 | | /// <summary>Initializes new instance of <see cref="ManagedIdentityTokenProvider"/> class with default <see cref |
| 24 | 18 | | public ManagedIdentityTokenProvider() : this(new AzureServiceTokenProvider()){} |
| | 19 | |
|
| | 20 | | /// <summary>Initializes new instance of <see cref="ManagedIdentityTokenProvider"/> class with <see cref="AzureS |
| | 21 | | /// <remarks>Call that constructore to set <see cref="AzureServiceTokenProvider"/> with required Managed Identit |
| 12 | 22 | | public ManagedIdentityTokenProvider(AzureServiceTokenProvider azureServiceTokenProvider) |
| | 23 | | { |
| 12 | 24 | | this.azureServiceTokenProvider = azureServiceTokenProvider; |
| 12 | 25 | | } |
| | 26 | |
|
| | 27 | | /// <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 | | { |
| 0 | 35 | | string accessToken = await azureServiceTokenProvider.GetAccessTokenAsync(Constants.AadServiceBusAudience).Co |
| 0 | 36 | | return new JsonSecurityToken(accessToken, appliesTo); |
| 0 | 37 | | } |
| | 38 | | } |
| | 39 | | } |