@@ -26,7 +26,7 @@ namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
26
26
/// </summary>
27
27
public class ProtectedFileTokenCache : TokenCache
28
28
{
29
- public static readonly string CacheFileName = Path . Combine ( AzurePowerShell . ProfileDirectory , "TokenCache.dat" ) ;
29
+ private static readonly string CacheFileName = Path . Combine ( AzurePowerShell . ProfileDirectory , "TokenCache.dat" ) ;
30
30
31
31
private static readonly object fileLock = new object ( ) ;
32
32
@@ -44,29 +44,39 @@ public static ProtectedFileTokenCache Instance
44
44
// Initializes the cache against a local file.
45
45
// If the file is already present, it loads its content in the ADAL cache
46
46
private ProtectedFileTokenCache ( )
47
+ {
48
+ Initialize ( CacheFileName ) ;
49
+ }
50
+
51
+ private void Initialize ( string fileName )
47
52
{
48
53
AfterAccess = AfterAccessNotification ;
49
54
BeforeAccess = BeforeAccessNotification ;
50
55
lock ( fileLock )
51
56
{
52
- if ( ProfileClient . DataStore . FileExists ( CacheFileName ) )
57
+ if ( ProfileClient . DataStore . FileExists ( fileName ) )
53
58
{
54
- var existingData = ProfileClient . DataStore . ReadFileAsBytes ( CacheFileName ) ;
59
+ var existingData = ProfileClient . DataStore . ReadFileAsBytes ( fileName ) ;
55
60
if ( existingData != null )
56
61
{
57
62
try
58
63
{
59
64
Deserialize ( ProtectedData . Unprotect ( existingData , null , DataProtectionScope . CurrentUser ) ) ;
60
65
}
61
- catch ( CryptographicException )
66
+ catch ( CryptographicException )
62
67
{
63
- ProfileClient . DataStore . DeleteFile ( CacheFileName ) ;
68
+ ProfileClient . DataStore . DeleteFile ( fileName ) ;
64
69
}
65
70
}
66
71
}
67
72
}
68
73
}
69
74
75
+ public ProtectedFileTokenCache ( string cacheFile )
76
+ {
77
+ Initialize ( cacheFile ) ;
78
+ }
79
+
70
80
// Empties the persistent store.
71
81
public override void Clear ( )
72
82
{
0 commit comments