Skip to content

Commit ba596e8

Browse files
committed
Get ADAL token cache from AzureContext
1 parent d0332c1 commit ba596e8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/ResourceManager/KeyVault/Commands.KeyVault/Models/DataServiceCredential.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System;
1818
using System.Linq;
1919
using System.Threading.Tasks;
20+
using Microsoft.IdentityModel.Clients.ActiveDirectory;
2021
using KeyVaultProperties = Microsoft.Azure.Commands.KeyVault.Properties;
2122

2223
namespace Microsoft.Azure.Commands.KeyVault.Models
@@ -85,8 +86,19 @@ private Tuple<IAccessToken, string> GetToken(IAuthenticationFactory authFactory,
8586

8687
try
8788
{
89+
var tokenCache = AzureSession.TokenCache;
90+
if (context.TokenCache != null && context.TokenCache.Length > 0)
91+
{
92+
tokenCache = new TokenCache(context.TokenCache);
93+
}
94+
8895
var accesstoken = authFactory.Authenticate(context.Account, context.Environment, TenantId, null, ShowDialog.Never,
89-
resourceIdEndpoint);
96+
tokenCache, resourceIdEndpoint);
97+
98+
if (context.TokenCache != null && context.TokenCache.Length > 0)
99+
{
100+
context.TokenCache = tokenCache.Serialize();
101+
}
90102

91103
return Tuple.Create(accesstoken, context.Environment.Endpoints[resourceIdEndpoint]);
92104
}

0 commit comments

Comments
 (0)