|
1 |
| -import type { Disposable, QuickInputButton } from 'vscode'; |
2 |
| -import { env, ThemeIcon, Uri, window } from 'vscode'; |
3 | 1 | import { HostingIntegrationId } from '../../../constants.integrations';
|
4 |
| -import { base64 } from '../../../system/string'; |
5 |
| -import type { IntegrationAuthenticationSessionDescriptor } from './integrationAuthenticationProvider'; |
6 |
| -import { LocalIntegrationAuthenticationProvider } from './integrationAuthenticationProvider'; |
7 |
| -import type { ProviderAuthenticationSession } from './models'; |
| 2 | +import { CloudIntegrationAuthenticationProvider } from './integrationAuthenticationProvider'; |
8 | 3 |
|
9 |
| -export class AzureDevOpsAuthenticationProvider extends LocalIntegrationAuthenticationProvider<HostingIntegrationId.AzureDevOps> { |
| 4 | +export class AzureDevOpsAuthenticationProvider extends CloudIntegrationAuthenticationProvider<HostingIntegrationId.AzureDevOps> { |
10 | 5 | protected override get authProviderId(): HostingIntegrationId.AzureDevOps {
|
11 | 6 | return HostingIntegrationId.AzureDevOps;
|
12 | 7 | }
|
13 |
| - |
14 |
| - override async createSession( |
15 |
| - descriptor: IntegrationAuthenticationSessionDescriptor, |
16 |
| - ): Promise<ProviderAuthenticationSession | undefined> { |
17 |
| - let azureOrganization: string | undefined = descriptor.organization as string | undefined; |
18 |
| - if (!azureOrganization) { |
19 |
| - const orgInput = window.createInputBox(); |
20 |
| - orgInput.ignoreFocusOut = true; |
21 |
| - const orgInputDisposables: Disposable[] = []; |
22 |
| - try { |
23 |
| - azureOrganization = await new Promise<string | undefined>(resolve => { |
24 |
| - orgInputDisposables.push( |
25 |
| - orgInput.onDidHide(() => resolve(undefined)), |
26 |
| - orgInput.onDidChangeValue(() => (orgInput.validationMessage = undefined)), |
27 |
| - orgInput.onDidAccept(() => { |
28 |
| - const value = orgInput.value.trim(); |
29 |
| - if (!value) { |
30 |
| - orgInput.validationMessage = 'An organization is required'; |
31 |
| - return; |
32 |
| - } |
33 |
| - |
34 |
| - resolve(value); |
35 |
| - }), |
36 |
| - ); |
37 |
| - |
38 |
| - orgInput.title = `Azure DevOps Authentication \u2022 ${descriptor.domain}`; |
39 |
| - orgInput.placeholder = 'Organization'; |
40 |
| - orgInput.prompt = 'Enter your Azure DevOps organization'; |
41 |
| - orgInput.show(); |
42 |
| - }); |
43 |
| - } finally { |
44 |
| - orgInput.dispose(); |
45 |
| - orgInputDisposables.forEach(d => void d.dispose()); |
46 |
| - } |
47 |
| - } |
48 |
| - |
49 |
| - if (!azureOrganization) return undefined; |
50 |
| - |
51 |
| - const tokenInput = window.createInputBox(); |
52 |
| - tokenInput.ignoreFocusOut = true; |
53 |
| - |
54 |
| - const disposables: Disposable[] = []; |
55 |
| - |
56 |
| - let token; |
57 |
| - try { |
58 |
| - const infoButton: QuickInputButton = { |
59 |
| - iconPath: new ThemeIcon(`link-external`), |
60 |
| - tooltip: 'Open the Azure DevOps Access Tokens Page', |
61 |
| - }; |
62 |
| - |
63 |
| - token = await new Promise<string | undefined>(resolve => { |
64 |
| - disposables.push( |
65 |
| - tokenInput.onDidHide(() => resolve(undefined)), |
66 |
| - tokenInput.onDidChangeValue(() => (tokenInput.validationMessage = undefined)), |
67 |
| - tokenInput.onDidAccept(() => { |
68 |
| - const value = tokenInput.value.trim(); |
69 |
| - if (!value) { |
70 |
| - tokenInput.validationMessage = 'A personal access token is required'; |
71 |
| - return; |
72 |
| - } |
73 |
| - |
74 |
| - resolve(value); |
75 |
| - }), |
76 |
| - tokenInput.onDidTriggerButton(e => { |
77 |
| - if (e === infoButton) { |
78 |
| - void env.openExternal( |
79 |
| - Uri.parse(`https://${descriptor.domain}/${azureOrganization}/_usersSettings/tokens`), |
80 |
| - ); |
81 |
| - } |
82 |
| - }), |
83 |
| - ); |
84 |
| - |
85 |
| - tokenInput.password = true; |
86 |
| - tokenInput.title = `Azure DevOps Authentication \u2022 ${descriptor.domain}`; |
87 |
| - tokenInput.placeholder = `Requires ${descriptor.scopes.join(', ') ?? 'all'} scopes`; |
88 |
| - tokenInput.prompt = `Paste your [Azure DevOps Personal Access Token](https://${descriptor.domain}/${azureOrganization}/_usersSettings/tokens "Get your Azure DevOps Access Token")`; |
89 |
| - tokenInput.buttons = [infoButton]; |
90 |
| - |
91 |
| - tokenInput.show(); |
92 |
| - }); |
93 |
| - } finally { |
94 |
| - tokenInput.dispose(); |
95 |
| - disposables.forEach(d => void d.dispose()); |
96 |
| - } |
97 |
| - |
98 |
| - if (!token) return undefined; |
99 |
| - |
100 |
| - return { |
101 |
| - id: this.configuredIntegrationService.getSessionId(descriptor), |
102 |
| - accessToken: base64(`:${token}`), |
103 |
| - scopes: descriptor.scopes, |
104 |
| - account: { |
105 |
| - id: '', |
106 |
| - label: '', |
107 |
| - }, |
108 |
| - cloud: false, |
109 |
| - domain: descriptor.domain, |
110 |
| - }; |
111 |
| - } |
112 | 8 | }
|
0 commit comments