Skip to content

Commit fd6ca08

Browse files
author
Hovsep
committed
Merge pull request Azure#2382 from seanbamsft/authfix
Key Vault: Ensure cached tokens are used during authentication
2 parents 49fb96f + ba596e8 commit fd6ca08

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

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

Lines changed: 14 additions & 2 deletions
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
{
88-
var accesstoken = authFactory.Authenticate(context.Account, context.Environment, TenantId, null, ShowDialog.Auto,
89-
resourceIdEndpoint);
89+
var tokenCache = AzureSession.TokenCache;
90+
if (context.TokenCache != null && context.TokenCache.Length > 0)
91+
{
92+
tokenCache = new TokenCache(context.TokenCache);
93+
}
94+
95+
var accesstoken = authFactory.Authenticate(context.Account, context.Environment, TenantId, null, ShowDialog.Never,
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)