Merge pull request #2706 from Dokploy/2673-bitbucket-deployments-are-broken-auth-token-wont-work

fix(bitbucket): enhance Bitbucket authentication handling
This commit is contained in:
Mauricio Siu
2025-09-27 02:58:49 -06:00
committed by GitHub
@@ -31,29 +31,51 @@ export const getBitbucketCloneUrl = (
apiToken?: string | null; apiToken?: string | null;
bitbucketUsername?: string | null; bitbucketUsername?: string | null;
appPassword?: string | null; appPassword?: string | null;
bitbucketEmail?: string | null;
bitbucketWorkspaceName?: string | null;
} | null, } | null,
repoClone: string, repoClone: string,
) => { ) => {
if (!bitbucketProvider) { if (!bitbucketProvider) {
throw new Error("Bitbucket provider is required"); throw new Error("Bitbucket provider is required");
} }
return bitbucketProvider.apiToken
? `https://x-token-auth:${bitbucketProvider.apiToken}@${repoClone}` if (bitbucketProvider.apiToken) {
: `https://${bitbucketProvider.bitbucketUsername}:${bitbucketProvider.appPassword}@${repoClone}`; return `https://x-bitbucket-api-token-auth:${bitbucketProvider.apiToken}@${repoClone}`;
}
// For app passwords, use username:app_password format
if (!bitbucketProvider.bitbucketUsername || !bitbucketProvider.appPassword) {
throw new Error(
"Username and app password are required when not using API token",
);
}
return `https://${bitbucketProvider.bitbucketUsername}:${bitbucketProvider.appPassword}@${repoClone}`;
}; };
export const getBitbucketHeaders = (bitbucketProvider: Bitbucket) => { export const getBitbucketHeaders = (bitbucketProvider: Bitbucket) => {
if (bitbucketProvider.apiToken) { if (bitbucketProvider.apiToken) {
// For API tokens, use HTTP Basic auth with email and token // According to Bitbucket official docs, for API calls with API tokens:
// According to Bitbucket docs: email:token for API calls // "You will need both your Atlassian account email and an API token"
const email = // Use: {atlassian_account_email}:{api_token}
bitbucketProvider.bitbucketEmail || bitbucketProvider.bitbucketUsername;
if (!bitbucketProvider.bitbucketEmail) {
throw new Error(
"Atlassian account email is required when using API token for API calls",
);
}
return { return {
Authorization: `Basic ${Buffer.from(`${email}:${bitbucketProvider.apiToken}`).toString("base64")}`, Authorization: `Basic ${Buffer.from(`${bitbucketProvider.bitbucketEmail}:${bitbucketProvider.apiToken}`).toString("base64")}`,
}; };
} }
// For app passwords, use HTTP Basic auth with username and app password // For app passwords, use HTTP Basic auth with username and app password
if (!bitbucketProvider.bitbucketUsername || !bitbucketProvider.appPassword) {
throw new Error(
"Username and app password are required when not using API token",
);
}
return { return {
Authorization: `Basic ${Buffer.from(`${bitbucketProvider.bitbucketUsername}:${bitbucketProvider.appPassword}`).toString("base64")}`, Authorization: `Basic ${Buffer.from(`${bitbucketProvider.bitbucketUsername}:${bitbucketProvider.appPassword}`).toString("base64")}`,
}; };