Bitbucket Cloud - API Token Support

Signed-off-by: Andre Wanlin <awanlin@spotify.com>
This commit is contained in:
Andre Wanlin
2025-11-17 12:49:43 -06:00
parent dd54fffedc
commit fa255f530a
12 changed files with 223 additions and 84 deletions
@@ -155,14 +155,17 @@ export class BitbucketCloudClient {
private getAuthHeaders(): Record<string, string> {
const headers: Record<string, string> = {};
if (this.config.username) {
if (
this.config.username &&
(this.config.token ?? this.config.appPassword)
) {
const buffer = Buffer.from(
`${this.config.username}:${this.config.appPassword}`,
`${this.config.username}:${
this.config.token ?? this.config.appPassword
}`,
'utf8',
);
headers.Authorization = `Basic ${buffer.toString('base64')}`;
} else if (this.config.token) {
headers.Authorization = `Bearer ${this.config.token}`;
}
return headers;
@@ -21,22 +21,24 @@ export const getBitbucketClient = (config: {
username?: string;
appPassword?: string;
}) => {
if (config.username && config.appPassword) {
if (config.token) {
return new Bitbucket({
auth: {
token: config.token,
},
});
} else if (config.username && config.appPassword) {
// TODO: appPassword can be removed once fully
// deprecated by BitBucket on 9th June 2026.
return new Bitbucket({
auth: {
username: config.username,
password: config.appPassword,
},
});
} else if (config.token) {
return new Bitbucket({
auth: {
token: config.token,
},
});
}
throw new Error(
`Authorization has not been provided for Bitbucket Cloud. Please add either username + appPassword to the Integrations config or a user login auth token`,
`Authorization has not been provided for Bitbucket Cloud. Please add either provide a username and token or username and appPassword to the Integrations config`,
);
};
@@ -45,12 +47,13 @@ export const getAuthorizationHeader = (config: {
appPassword?: string;
token?: string;
}) => {
if (config.username && config.appPassword) {
// TODO: appPassword can be removed once fully
// deprecated by BitBucket on 9th June 2026.
if (config.username && (config.token ?? config.appPassword)) {
const buffer = Buffer.from(
`${config.username}:${config.appPassword}`,
`${config.username}:${config.token ?? config.appPassword}`,
'utf8',
);
return `Basic ${buffer.toString('base64')}`;
}
@@ -59,6 +62,6 @@ export const getAuthorizationHeader = (config: {
}
throw new Error(
`Authorization has not been provided for Bitbucket Cloud. Please add either username + appPassword to the Integrations config or a user login auth token`,
`Authorization has not been provided for Bitbucket Cloud. Please add either provide a username and token or username and appPassword to the Integrations config`,
);
};
@@ -153,9 +153,9 @@ const createBitbucketServerRepository = async (opts: {
};
const getAuthorizationHeader = (config: BitbucketIntegrationConfig) => {
if (config.username && config.appPassword) {
if (config.username && (config.token ?? config.appPassword)) {
const buffer = Buffer.from(
`${config.username}:${config.appPassword}`,
`${config.username}:${config.token ?? config.appPassword}`,
'utf8',
);
@@ -167,7 +167,7 @@ const getAuthorizationHeader = (config: BitbucketIntegrationConfig) => {
}
throw new Error(
`Authorization has not been provided for Bitbucket. Please add either username + appPassword or token to the Integrations config`,
`Authorization has not been provided for Bitbucket. Please add either provide a username and token or username and appPassword to the Integrations config`,
);
};