Skip to content

Commit 4f86085

Browse files
committed
fix bitbucket app password auth case
1 parent 5c21ca7 commit 4f86085

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

packages/backend/src/bitbucket.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const getBitbucketReposFromConfig = async (config: BitbucketConnectionCon
6464
const token = await getTokenFromConfig(config.token, orgId, db, logger);
6565

6666
//const deploymentType = config.deploymentType;
67-
const client = cloudClient(token);
67+
const client = cloudClient(config.user, token);
6868

6969
let allRepos: BitbucketRepository[] = [];
7070
let notFound: {
@@ -101,12 +101,14 @@ export const getBitbucketReposFromConfig = async (config: BitbucketConnectionCon
101101
};
102102
}
103103

104-
function cloudClient(token: string | undefined): BitbucketClient {
104+
function cloudClient(user: string | undefined, token: string | undefined): BitbucketClient {
105+
106+
const authorizationString = !user || user == "x-token-auth" ? `Bearer ${token}` : `Basic ${Buffer.from(`${user}:${token}`).toString('base64')}`;
105107
const clientOptions: ClientOptions = {
106108
baseUrl: BITBUCKET_CLOUD_API,
107109
headers: {
108110
Accept: "application/json",
109-
Authorization: `Bearer ${token}`,
111+
Authorization: authorizationString,
110112
},
111113
};
112114

packages/backend/src/repoManager.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export class RepoManager implements IRepoManager {
177177
return undefined;
178178
}
179179

180-
const username = (() => {
180+
let username = (() => {
181181
switch (repo.external_codeHostType) {
182182
case 'gitlab':
183183
return 'oauth2';
@@ -202,6 +202,11 @@ export class RepoManager implements IRepoManager {
202202
if (config.token) {
203203
password = await getTokenFromConfig(config.token, connection.orgId, db, this.logger);
204204
if (password) {
205+
// If we're using a bitbucket connection, check to see if we're provided a username
206+
if (connection.connectionType === 'bitbucket') {
207+
const bitbucketConfig = config as BitbucketConnectionConfig;
208+
username = bitbucketConfig.user ?? "x-token-auth";
209+
}
205210
break;
206211
}
207212
}

0 commit comments

Comments
 (0)