1- using Microsoft . IdentityModel . Clients . ActiveDirectory ;
2- using System ;
3- using System . Collections . Generic ;
1+ /*
2+ The MIT License (MIT)
3+
4+ Copyright (c) 2015 Microsoft Corporation
5+
6+ Permission is hereby granted, free of charge, to any person obtaining a copy
7+ of this software and associated documentation files (the "Software"), to deal
8+ in the Software without restriction, including without limitation the rights
9+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ copies of the Software, and to permit persons to whom the Software is
11+ furnished to do so, subject to the following conditions:
12+
13+ The above copyright notice and this permission notice shall be included in all
14+ copies or substantial portions of the Software.
15+
16+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+ SOFTWARE.
23+ */
24+
25+ using Microsoft . IdentityModel . Clients . ActiveDirectory ;
426using System . IO ;
5- using System . Linq ;
6- using System . Text ;
7- using System . Threading . Tasks ;
8- using System . Security ;
927using System . Security . Cryptography ;
1028
1129namespace TodoListClient
@@ -20,7 +38,7 @@ class FileCache : TokenCache
2038
2139 // Initializes the cache against a local file.
2240 // If the file is already rpesent, it loads its content in the ADAL cache
23- public FileCache ( string filePath = @".\TokenCache.dat" )
41+ public FileCache ( string filePath = @".\TokenCache.dat" )
2442 {
2543 CacheFilePath = filePath ;
2644 this . AfterAccess = AfterAccessNotification ;
@@ -40,11 +58,11 @@ public override void Clear()
4058
4159 // Triggered right before ADAL needs to access the cache.
4260 // Reload the cache from the persistent store in case it changed since the last access.
43- void BeforeAccessNotification ( TokenCacheNotificationArgs args )
61+ void BeforeAccessNotification ( TokenCacheNotificationArgs args )
4462 {
4563 lock ( FileLock )
4664 {
47- this . Deserialize ( File . Exists ( CacheFilePath ) ? ProtectedData . Unprotect ( File . ReadAllBytes ( CacheFilePath ) , null , DataProtectionScope . CurrentUser ) : null ) ;
65+ this . Deserialize ( File . Exists ( CacheFilePath ) ? ProtectedData . Unprotect ( File . ReadAllBytes ( CacheFilePath ) , null , DataProtectionScope . CurrentUser ) : null ) ;
4866 }
4967 }
5068
@@ -55,14 +73,14 @@ void AfterAccessNotification(TokenCacheNotificationArgs args)
5573 if ( this . HasStateChanged )
5674 {
5775 lock ( FileLock )
58- {
76+ {
5977 // reflect changes in the persistent store
60- File . WriteAllBytes ( CacheFilePath , ProtectedData . Protect ( this . Serialize ( ) , null , DataProtectionScope . CurrentUser ) ) ;
78+ File . WriteAllBytes ( CacheFilePath , ProtectedData . Protect ( this . Serialize ( ) , null , DataProtectionScope . CurrentUser ) ) ;
6179 // once the write operation took place, restore the HasStateChanged bit to false
6280 this . HasStateChanged = false ;
63- }
81+ }
6482 }
6583 }
6684 }
6785
68- }
86+ }
0 commit comments