@@ -15,48 +15,73 @@ public EntraAuthenticationDiagnostic(ICommandContext context)
1515
1616 protected override async Task < bool > RunInternalAsync ( StringBuilder log , IList < string > additionalFiles )
1717 {
18- var entraAuth = new EntraAuthentication ( CommandContext , new PublicClientConfig
19- {
20- UseSharedCache = true ,
21- } ) ;
18+ var failures = new List < Exception > ( ) ;
2219
23- log . Append ( "Gathering MSAL token cache data..." ) ;
24- StorageCreationProperties cacheProps = entraAuth . CreateUserTokenCacheProps ( true ) ;
25- log . AppendLine ( " OK" ) ;
26- log . AppendLine ( $ "CacheDirectory: { cacheProps . CacheDirectory } ") ;
27- log . AppendLine ( $ "CacheFileName: { cacheProps . CacheFileName } ") ;
28- log . AppendLine ( $ "CacheFilePath: { cacheProps . CacheFilePath } ") ;
20+ await RunCacheDiagnosticAsync ( "Shared Microsoft developer tools" , true , log , failures ) ;
21+ log . AppendLine ( ) ;
22+ await RunCacheDiagnosticAsync ( "Git Credential Manager" , false , log , failures ) ;
2923
30- if ( PlatformUtils . IsMacOS ( ) )
24+ if ( failures . Count == 1 )
3125 {
32- log . AppendLine ( $ "MacKeyChainAccountName: { cacheProps . MacKeyChainAccountName } ") ;
33- log . AppendLine ( $ "MacKeyChainServiceName: { cacheProps . MacKeyChainServiceName } ") ;
26+ throw failures [ 0 ] ;
3427 }
35- else if ( PlatformUtils . IsLinux ( ) )
28+
29+ if ( failures . Count > 1 )
3630 {
37- log . AppendLine ( $ "KeyringCollection: { cacheProps . KeyringCollection } ") ;
38- log . AppendLine ( $ "KeyringSchemaName: { cacheProps . KeyringSchemaName } ") ;
39- log . AppendLine ( $ "KeyringSecretLabel: { cacheProps . KeyringSecretLabel } ") ;
40- log . AppendLine ( $ "KeyringAttribute1: ({ cacheProps . KeyringAttribute1 . Key } ,{ cacheProps . KeyringAttribute1 . Value } )") ;
41- log . AppendLine ( $ "KeyringAttribute2: ({ cacheProps . KeyringAttribute2 . Key } ,{ cacheProps . KeyringAttribute2 . Value } )") ;
31+ throw new AggregateException ( "Multiple MSAL token cache diagnostics failed." , failures ) ;
4232 }
4333
44- log . Append ( "Creating cache helper..." ) ;
45- var cacheHelper = await MsalCacheHelper . CreateAsync ( cacheProps ) ;
46- log . AppendLine ( " OK" ) ;
34+ return true ;
35+ }
36+
37+ private async Task RunCacheDiagnosticAsync (
38+ string cacheName ,
39+ bool useSharedCache ,
40+ StringBuilder log ,
41+ ICollection < Exception > failures )
42+ {
43+ log . AppendLine ( $ "{ cacheName } cache") ;
44+
45+ var entraAuth = new EntraAuthentication ( CommandContext , new PublicClientConfig
46+ {
47+ UseSharedCache = useSharedCache ,
48+ } ) ;
49+
4750 try
4851 {
52+ log . Append ( "Gathering MSAL token cache data..." ) ;
53+ StorageCreationProperties cacheProps = entraAuth . CreateUserTokenCacheProps ( true ) ;
54+ log . AppendLine ( " OK" ) ;
55+ log . AppendLine ( $ "CacheDirectory: { cacheProps . CacheDirectory } ") ;
56+ log . AppendLine ( $ "CacheFileName: { cacheProps . CacheFileName } ") ;
57+ log . AppendLine ( $ "CacheFilePath: { cacheProps . CacheFilePath } ") ;
58+
59+ if ( PlatformUtils . IsMacOS ( ) )
60+ {
61+ log . AppendLine ( $ "MacKeyChainAccountName: { cacheProps . MacKeyChainAccountName } ") ;
62+ log . AppendLine ( $ "MacKeyChainServiceName: { cacheProps . MacKeyChainServiceName } ") ;
63+ }
64+ else if ( PlatformUtils . IsLinux ( ) )
65+ {
66+ log . AppendLine ( $ "KeyringCollection: { cacheProps . KeyringCollection } ") ;
67+ log . AppendLine ( $ "KeyringSchemaName: { cacheProps . KeyringSchemaName } ") ;
68+ log . AppendLine ( $ "KeyringSecretLabel: { cacheProps . KeyringSecretLabel } ") ;
69+ log . AppendLine ( $ "KeyringAttribute1: ({ cacheProps . KeyringAttribute1 . Key } ,{ cacheProps . KeyringAttribute1 . Value } )") ;
70+ log . AppendLine ( $ "KeyringAttribute2: ({ cacheProps . KeyringAttribute2 . Key } ,{ cacheProps . KeyringAttribute2 . Value } )") ;
71+ }
72+
73+ log . Append ( "Creating cache helper..." ) ;
74+ var cacheHelper = await MsalCacheHelper . CreateAsync ( cacheProps ) ;
75+ log . AppendLine ( " OK" ) ;
4976 log . Append ( "Verifying MSAL token cache persistence..." ) ;
5077 cacheHelper . VerifyPersistence ( ) ;
5178 log . AppendLine ( " OK" ) ;
5279 }
53- catch ( Exception )
80+ catch ( Exception ex )
5481 {
5582 log . AppendLine ( " Failed" ) ;
56- throw ;
83+ failures . Add ( new Exception ( $ " { cacheName } cache diagnostic failed." , ex ) ) ;
5784 }
58-
59- return true ;
6085 }
6186 }
6287}
0 commit comments