| | 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.Diagnostics; |
| | 7 | | using System; |
| | 8 | | using System.Linq; |
| | 9 | | using System.Threading.Tasks; |
| | 10 | | using Microsoft.Azure.Amqp; |
| | 11 | |
|
| | 12 | | /// <summary> |
| | 13 | | /// Provides an adapter from TokenProvider to ICbsTokenProvider for AMQP CBS usage. |
| | 14 | | /// </summary> |
| | 15 | | sealed class TokenProviderAdapter : ICbsTokenProvider |
| | 16 | | { |
| | 17 | | readonly ITokenProvider tokenProvider; |
| | 18 | | readonly TimeSpan operationTimeout; |
| | 19 | |
|
| 12 | 20 | | public TokenProviderAdapter(ITokenProvider tokenProvider, TimeSpan operationTimeout) |
| | 21 | | { |
| | 22 | | Debug.Assert(tokenProvider != null, "tokenProvider cannot be null"); |
| 12 | 23 | | this.tokenProvider = tokenProvider; |
| 12 | 24 | | this.operationTimeout = operationTimeout; |
| 12 | 25 | | } |
| | 26 | |
|
| | 27 | | public async Task<CbsToken> GetTokenAsync(Uri namespaceAddress, string appliesTo, string[] requiredClaims) |
| | 28 | | { |
| 0 | 29 | | var claim = requiredClaims?.FirstOrDefault(); |
| 0 | 30 | | var securityToken = await this.tokenProvider.GetTokenAsync(appliesTo, this.operationTimeout).ConfigureAwait( |
| 0 | 31 | | return new CbsToken(securityToken.TokenValue, CbsConstants.ServiceBusSasTokenType, securityToken.ExpiresAtUt |
| 0 | 32 | | } |
| | 33 | | } |
| | 34 | | } |