|
1 | 1 | using Microsoft.Graph.Cli.Authentication; |
| 2 | +using Microsoft.Graph.Cli.Utils; |
2 | 3 | using System.CommandLine; |
3 | 4 | using System.CommandLine.Invocation; |
4 | 5 |
|
5 | 6 | namespace Microsoft.Graph.Cli.Commands.Authentication; |
6 | 7 |
|
7 | 8 | class LoginCommand |
8 | 9 | { |
9 | | - private IAuthenticationService authenticationService; |
| 10 | + private AuthenticationServiceFactory authenticationServiceFactory; |
10 | 11 |
|
11 | | - public LoginCommand(IAuthenticationService authenticationService) { |
12 | | - this.authenticationService = authenticationService; |
| 12 | + public LoginCommand(AuthenticationServiceFactory authenticationServiceFactory) { |
| 13 | + this.authenticationServiceFactory = authenticationServiceFactory; |
13 | 14 | } |
14 | 15 |
|
15 | | - public Command Build() { |
| 16 | + public Command Build(bool persistToken = false) { |
16 | 17 | var loginCommand = new Command("login", "Login and store the session for use in subsequent commands"); |
17 | 18 | var scopes = new Option<string>("--scopes", "The login scopes e.g. User.Read"); |
18 | 19 | scopes.IsRequired = true; |
19 | 20 | scopes.Arity = ArgumentArity.OneOrMore; |
20 | 21 | loginCommand.AddOption(scopes); |
21 | | - loginCommand.Handler = CommandHandler.Create<string[]>(async (scopes) => |
| 22 | + |
| 23 | + var strategy = new Option<AuthenticationStrategy>("--strategy", () => Constants.defaultAuthStrategy, "The authentication strategy to use."); |
| 24 | + loginCommand.AddOption(strategy); |
| 25 | + |
| 26 | + loginCommand.Handler = CommandHandler.Create<string[], AuthenticationStrategy>(async (scopes, strategy) => |
22 | 27 | { |
23 | | - await this.authenticationService.LoginAsync(scopes); |
| 28 | + var authService = await this.authenticationServiceFactory.GetAuthenticationServiceAsync(strategy, persistToken); |
| 29 | + await authService.LoginAsync(scopes); |
24 | 30 | }); |
25 | 31 |
|
26 | 32 | return loginCommand; |
|
0 commit comments