@@ -36,17 +36,18 @@ static async Task<int> Main(string[] args)
3636 var config = configBuilder . Build ( ) ;
3737
3838 var authSettings = config . GetSection ( nameof ( AuthenticationOptions ) ) . Get < AuthenticationOptions > ( ) ;
39- var authServiceFactory = new AuthenticationServiceFactory ( new PathUtility ( ) ) ;
39+ var pathUtil = new PathUtility ( ) ;
40+ var authServiceFactory = new AuthenticationServiceFactory ( pathUtil , authSettings ) ;
4041 var authStrategy = AuthenticationStrategy . DeviceCode ;
4142
42- var credential = await authServiceFactory . GetTokenCredentialAsync ( authStrategy , authSettings ? . TenantId , authSettings ? . ClientId ) ;
43+ var credential = await authServiceFactory . GetTokenCredentialAsync ( authStrategy , authSettings ? . TenantId , authSettings ? . ClientId , authSettings ? . ClientCertificateName , authSettings ? . ClientCertificateThumbPrint ) ;
4344 var authProvider = new AzureIdentityAuthenticationProvider ( credential , new string [ ] { "graph.microsoft.com" } ) ;
4445
4546 var assemblyVersion = Assembly . GetExecutingAssembly ( ) . GetName ( ) . Version ;
4647 var options = new GraphClientOptions
4748 {
4849 GraphProductPrefix = "graph-cli" ,
49- GraphServiceLibraryClientVersion = $ "{ assemblyVersion . Major } .{ assemblyVersion . Minor } .{ assemblyVersion . Build } ",
50+ GraphServiceLibraryClientVersion = $ "{ assemblyVersion ? . Major ?? 0 } .{ assemblyVersion ? . Minor ?? 0 } .{ assemblyVersion ? . Build ?? 0 } ",
5051 GraphServiceTargetVersion = "1.0"
5152 } ;
5253 using var httpClient = GraphCliClientFactory . GetDefaultClient ( options ) ;
@@ -57,7 +58,8 @@ static async Task<int> Main(string[] args)
5758 var loginCommand = new LoginCommand ( authServiceFactory ) ;
5859 commands . Add ( loginCommand . Build ( ) ) ;
5960
60- var logoutCommand = new LogoutCommand ( new LogoutService ( ) ) ;
61+ var authCacheUtil = new AuthenticationCacheUtility ( pathUtil ) ;
62+ var logoutCommand = new LogoutCommand ( new LogoutService ( authCacheUtil ) ) ;
6163 commands . Add ( logoutCommand . Build ( ) ) ;
6264
6365 var builder = BuildCommandLine ( client , commands ) . UseDefaults ( ) . UseHost ( CreateHostBuilder ) ;
@@ -73,20 +75,23 @@ static async Task<int> Main(string[] args)
7375 } ) ;
7476 builder . UseExceptionHandler ( ( ex , context ) =>
7577 {
76- if ( ex is AuthenticationRequiredException )
77- {
78- Console . ResetColor ( ) ;
79- Console . ForegroundColor = ConsoleColor . Red ;
80- context . Console . Error . WriteLine ( "Token acquisition failed. Run mgc login command first to get an access token." ) ;
81- Console . ResetColor ( ) ;
82- }
83- else
78+ switch ( ex )
8479 {
85- Console . ResetColor ( ) ;
86- Console . ForegroundColor = ConsoleColor . Red ;
87- context . Console . Error . WriteLine ( ex . Message ) ;
88- context . Console . Error . WriteLine ( ex . StackTrace ) ;
89- Console . ResetColor ( ) ;
80+ case AuthenticationRequiredException :
81+ Console . ResetColor ( ) ;
82+ Console . ForegroundColor = ConsoleColor . Red ;
83+ context . Console . Error . WriteLine ( "Token acquisition failed. Run mgc login command first to get an access token." ) ;
84+ Console . ResetColor ( ) ;
85+ break ;
86+ case TaskCanceledException :
87+ break ;
88+ default :
89+ Console . ResetColor ( ) ;
90+ Console . ForegroundColor = ConsoleColor . Red ;
91+ context . Console . Error . WriteLine ( ex . Message ) ;
92+ context . Console . Error . WriteLine ( ex . StackTrace ) ;
93+ Console . ResetColor ( ) ;
94+ break ;
9095 }
9196 } ) ;
9297
0 commit comments