feat: add ScmAuth provider for Bitbucket Server

This fixes a bug where it used the same scopes as Bitbucket Cloud,
even though they are incompatible with Bitbucket Server.

Fixes #26803

Signed-off-by: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com>
This commit is contained in:
RedlineTriad
2024-09-24 15:23:28 +02:00
parent 481637b97d
commit f69821a0f8
2 changed files with 45 additions and 0 deletions
+10
View File
@@ -61,6 +61,16 @@ export class ScmAuth implements ScmAuthApi {
};
},
): ScmAuth;
static forBitbucketServer(
bitbucketAuthApi: OAuthApi,
options: {
host: string;
scopeMapping?: {
default?: string[];
repoWrite?: string[];
};
},
): ScmAuth;
static forGithub(
githubAuthApi: OAuthApi,
options?: {
@@ -251,6 +251,41 @@ export class ScmAuth implements ScmAuthApi {
});
}
/**
* Creates a new ScmAuth instance that handles authentication towards Bitbucket Server.
*
* The host option determines which URLs that are handled by this instance.
*
* The default scopes are:
*
* `PUBLIC_REPOS REPOS_READ`
*
* If the additional `repoWrite` permission is requested, these scopes are added:
*
* `REPO_WRITE`
*/
static forBitbucketServer(
bitbucketAuthApi: OAuthApi,
options: {
host: string;
scopeMapping?: {
default?: string[];
repoWrite?: string[];
};
},
): ScmAuth {
return this.forBitbucket(bitbucketAuthApi, {
host: options.host,
scopeMapping: {
default: options.scopeMapping?.default ?? [
'PUBLIC_REPOS',
'REPOS_READ',
],
repoWrite: options.scopeMapping?.repoWrite ?? ['REPO_WRITE'],
},
});
}
/**
* Merges together multiple ScmAuth instances into one that
* routes requests to the correct instance based on the URL.