|
3 | 3 | using System.Threading.Tasks; |
4 | 4 | using Azure.Core; |
5 | 5 | using Azure.Identity; |
| 6 | +using Microsoft.Extensions.Options; |
| 7 | +using Microsoft.Graph.Cli.Configuration; |
| 8 | +using Microsoft.Graph.Cli.IO; |
6 | 9 | using Microsoft.Graph.Cli.Utils; |
7 | 10 |
|
8 | 11 | namespace Microsoft.Graph.Cli.Authentication; |
9 | 12 |
|
10 | 13 | class AuthenticationServiceFactory { |
11 | | - public async Task<ILoginService> GetAuthenticationServiceAsync(AuthenticationStrategy strategy) { |
| 14 | + public async Task<ILoginService> GetAuthenticationServiceAsync(AuthenticationStrategy strategy, string tenantId, string clientId) { |
12 | 15 | switch (strategy) { |
13 | 16 | case AuthenticationStrategy.DeviceCode: |
14 | | - return await GetDeviceCodeLoginServiceAsync(); |
| 17 | + return await GetDeviceCodeLoginServiceAsync(tenantId, clientId); |
15 | 18 | default: |
16 | 19 | throw new InvalidOperationException($"The authentication strategy {strategy} is not supported"); |
17 | 20 | } |
18 | 21 |
|
19 | 22 | } |
20 | 23 |
|
21 | | - public async Task<TokenCredential> GetTokenCredentialAsync(AuthenticationStrategy strategy) { |
| 24 | + public async Task<TokenCredential> GetTokenCredentialAsync(AuthenticationStrategy strategy, string tenantId, string clientId) { |
22 | 25 | switch (strategy) { |
23 | 26 | case AuthenticationStrategy.DeviceCode: |
24 | | - return await GetDeviceCodeCredentialAsync(); |
| 27 | + return await GetDeviceCodeCredentialAsync(tenantId, clientId); |
25 | 28 | default: |
26 | 29 | throw new InvalidOperationException($"The authentication strategy {strategy} is not supported"); |
27 | 30 | } |
28 | 31 | } |
29 | 32 |
|
30 | | - private async Task<DeviceCodeLoginService> GetDeviceCodeLoginServiceAsync() { |
31 | | - var credential = await GetDeviceCodeCredentialAsync(); |
32 | | - return new(credential); |
| 33 | + private async Task<DeviceCodeLoginService> GetDeviceCodeLoginServiceAsync(string tenantId, string clientId) { |
| 34 | + var credential = await GetDeviceCodeCredentialAsync(tenantId, clientId); |
| 35 | + return new(credential, new PathUtility()); |
33 | 36 | } |
34 | 37 |
|
35 | | - private async Task<DeviceCodeCredential> GetDeviceCodeCredentialAsync() { |
| 38 | + private async Task<DeviceCodeCredential> GetDeviceCodeCredentialAsync(string tenantId, string clientId) { |
36 | 39 | DeviceCodeCredentialOptions credOptions = new() |
37 | 40 | { |
38 | | - ClientId = Constants.ClientId, |
39 | | - TenantId = Constants.TenantId |
| 41 | + ClientId = clientId, |
| 42 | + TenantId = tenantId, |
40 | 43 | }; |
41 | 44 |
|
42 | 45 | TokenCachePersistenceOptions tokenCacheOptions = new() { Name = Constants.TokenCacheName }; |
|
0 commit comments