|
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 BitbucketAuthenticationProvider extends LocalIntegrationAuthenticationProvider<HostingIntegrationId.Bitbucket> { |
| 4 | +export class BitbucketAuthenticationProvider extends CloudIntegrationAuthenticationProvider<HostingIntegrationId.Bitbucket> { |
10 | 5 | protected override get authProviderId(): HostingIntegrationId.Bitbucket { |
11 | 6 | return HostingIntegrationId.Bitbucket; |
12 | 7 | } |
13 | | - |
14 | | - override async createSession( |
15 | | - descriptor: IntegrationAuthenticationSessionDescriptor, |
16 | | - ): Promise<ProviderAuthenticationSession | undefined> { |
17 | | - let bitbucketUsername: string | undefined = descriptor.username as string | undefined; |
18 | | - if (!bitbucketUsername) { |
19 | | - const infoButton: QuickInputButton = { |
20 | | - iconPath: new ThemeIcon(`link-external`), |
21 | | - tooltip: 'Open the Bitbucket Settings Page', |
22 | | - }; |
23 | | - |
24 | | - const usernameInput = window.createInputBox(); |
25 | | - usernameInput.ignoreFocusOut = true; |
26 | | - const usernameInputDisposables: Disposable[] = []; |
27 | | - try { |
28 | | - bitbucketUsername = await new Promise<string | undefined>(resolve => { |
29 | | - usernameInputDisposables.push( |
30 | | - usernameInput.onDidHide(() => resolve(undefined)), |
31 | | - usernameInput.onDidChangeValue(() => (usernameInput.validationMessage = undefined)), |
32 | | - usernameInput.onDidAccept(() => { |
33 | | - const value = usernameInput.value.trim(); |
34 | | - if (!value) { |
35 | | - usernameInput.validationMessage = 'A Bitbucket username is required'; |
36 | | - return; |
37 | | - } |
38 | | - |
39 | | - resolve(value); |
40 | | - }), |
41 | | - usernameInput.onDidTriggerButton(e => { |
42 | | - if (e === infoButton) { |
43 | | - void env.openExternal(Uri.parse(`https://${descriptor.domain}/account/settings/`)); |
44 | | - } |
45 | | - }), |
46 | | - ); |
47 | | - |
48 | | - usernameInput.title = `Bitbucket Authentication \u2022 ${descriptor.domain}`; |
49 | | - usernameInput.placeholder = 'Username'; |
50 | | - usernameInput.prompt = `Enter your [Bitbucket Username](https://${descriptor.domain}/account/settings/ "Get your Bitbucket App Password")`; |
51 | | - usernameInput.show(); |
52 | | - }); |
53 | | - } finally { |
54 | | - usernameInput.dispose(); |
55 | | - usernameInputDisposables.forEach(d => void d.dispose()); |
56 | | - } |
57 | | - } |
58 | | - |
59 | | - if (!bitbucketUsername) return undefined; |
60 | | - |
61 | | - const appPasswordInput = window.createInputBox(); |
62 | | - appPasswordInput.ignoreFocusOut = true; |
63 | | - |
64 | | - const disposables: Disposable[] = []; |
65 | | - |
66 | | - let appPassword; |
67 | | - try { |
68 | | - const infoButton: QuickInputButton = { |
69 | | - iconPath: new ThemeIcon(`link-external`), |
70 | | - tooltip: 'Open the Bitbucket App Passwords Page', |
71 | | - }; |
72 | | - |
73 | | - appPassword = await new Promise<string | undefined>(resolve => { |
74 | | - disposables.push( |
75 | | - appPasswordInput.onDidHide(() => resolve(undefined)), |
76 | | - appPasswordInput.onDidChangeValue(() => (appPasswordInput.validationMessage = undefined)), |
77 | | - appPasswordInput.onDidAccept(() => { |
78 | | - const value = appPasswordInput.value.trim(); |
79 | | - if (!value) { |
80 | | - appPasswordInput.validationMessage = 'An app password is required'; |
81 | | - return; |
82 | | - } |
83 | | - |
84 | | - resolve(value); |
85 | | - }), |
86 | | - appPasswordInput.onDidTriggerButton(e => { |
87 | | - if (e === infoButton) { |
88 | | - void env.openExternal( |
89 | | - Uri.parse(`https://${descriptor.domain}/account/settings/app-passwords/`), |
90 | | - ); |
91 | | - } |
92 | | - }), |
93 | | - ); |
94 | | - |
95 | | - appPasswordInput.password = true; |
96 | | - appPasswordInput.title = `Bitbucket Authentication \u2022 ${descriptor.domain}`; |
97 | | - appPasswordInput.placeholder = `Requires ${descriptor.scopes.join(', ')} scopes`; |
98 | | - appPasswordInput.prompt = `Paste your [Bitbucket App Password](https://${descriptor.domain}/account/settings/app-passwords/ "Get your Bitbucket App Password")`; |
99 | | - appPasswordInput.buttons = [infoButton]; |
100 | | - |
101 | | - appPasswordInput.show(); |
102 | | - }); |
103 | | - } finally { |
104 | | - appPasswordInput.dispose(); |
105 | | - disposables.forEach(d => void d.dispose()); |
106 | | - } |
107 | | - |
108 | | - if (!appPassword) return undefined; |
109 | | - |
110 | | - return { |
111 | | - id: this.configuredIntegrationService.getSessionId(descriptor), |
112 | | - accessToken: base64(`${bitbucketUsername}:${appPassword}`), |
113 | | - scopes: descriptor.scopes, |
114 | | - account: { |
115 | | - id: '', |
116 | | - label: '', |
117 | | - }, |
118 | | - cloud: false, |
119 | | - domain: descriptor.domain, |
120 | | - }; |
121 | | - } |
122 | 8 | } |
0 commit comments