Skip to content

Commit c79f478

Browse files
Reduce required Bitbucket scopes (#20195)
1 parent 24d97c8 commit c79f478

File tree

5 files changed

+7
-19
lines changed

5 files changed

+7
-19
lines changed

components/public-api/typescript-common/src/auth-providers.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export namespace GitHubScope {
3737
export namespace BitbucketOAuthScopes {
3838
// https://confluence.atlassian.com/bitbucket/oauth-on-bitbucket-cloud-238027431.html
3939

40-
/** Read user info like name, e-mail adresses etc. */
40+
/** Read user info like name, e-mail addresses etc. */
4141
export const ACCOUNT_READ = "account";
4242
/** Access repo info, clone repo over https, read and write issues */
4343
export const REPOSITORY_READ = "repository";
@@ -47,16 +47,13 @@ export namespace BitbucketOAuthScopes {
4747
export const PULL_REQUEST_READ = "pullrequest";
4848
/** Create, comment and merge pull requests */
4949
export const PULL_REQUEST_WRITE = "pullrequest:write";
50-
/** Create, list web hooks */
51-
export const WEBHOOK = "webhook";
5250

5351
export const ALL = [
5452
ACCOUNT_READ,
5553
REPOSITORY_READ,
5654
REPOSITORY_WRITE,
5755
PULL_REQUEST_READ,
5856
PULL_REQUEST_WRITE,
59-
WEBHOOK,
6057
];
6158

6259
export const DEFAULT = ALL;

components/server/src/bitbucket-server/bitbucket-server-auth-provider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class BitbucketServerAuthProvider extends GenericAuthProvider {
6363
try {
6464
const username = await this.api.currentUsername(accessToken);
6565
const userProfile = await this.api.getUserProfile(accessToken, username);
66-
const avatarUrl = await this.api.getAvatarUrl(username);
66+
const avatarUrl = this.api.getAvatarUrl(username);
6767
return <AuthUserSetup>{
6868
authUser: {
6969
// e.g. 105
@@ -74,7 +74,7 @@ export class BitbucketServerAuthProvider extends GenericAuthProvider {
7474
name: userProfile.displayName!,
7575
avatarUrl,
7676
},
77-
currentScopes: BitbucketServerOAuthScopes.ALL,
77+
currentScopes: BitbucketServerOAuthScopes.Requirements.DEFAULT,
7878
};
7979
} catch (error) {
8080
log.error(`(${this.strategyName}) Reading current user info failed`, error, { error });

components/server/src/bitbucket-server/bitbucket-server-oauth-scopes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ export namespace BitbucketServerOAuthScopes {
2323
/**
2424
* Minimal required permission.
2525
*/
26-
DEFAULT: ALL,
26+
DEFAULT: [PUBLIC_REPOS, REPO_READ, REPO_WRITE],
2727
};
2828
}

components/server/src/bitbucket/bitbucket-oauth-scopes.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// https://confluence.atlassian.com/bitbucket/oauth-on-bitbucket-cloud-238027431.html
88

99
export namespace BitbucketOAuthScopes {
10-
/** Read user info like name, e-mail adresses etc. */
10+
/** Read user info like name, e-mail addresses etc. */
1111
export const ACCOUNT_READ = "account";
1212
/** Access repo info, clone repo over https, read and write issues */
1313
export const REPOSITORY_READ = "repository";
@@ -17,17 +17,8 @@ export namespace BitbucketOAuthScopes {
1717
export const PULL_REQUEST_READ = "pullrequest";
1818
/** Create, comment and merge pull requests */
1919
export const PULL_REQUEST_WRITE = "pullrequest:write";
20-
/** Create, list web hooks */
21-
export const WEBHOOK = "webhook";
2220

23-
export const ALL = [
24-
ACCOUNT_READ,
25-
REPOSITORY_READ,
26-
REPOSITORY_WRITE,
27-
PULL_REQUEST_READ,
28-
PULL_REQUEST_WRITE,
29-
WEBHOOK,
30-
];
21+
export const ALL = [ACCOUNT_READ, REPOSITORY_READ, REPOSITORY_WRITE, PULL_REQUEST_READ, PULL_REQUEST_WRITE];
3122

3223
export const Requirements = {
3324
/**

components/server/src/user/token-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class TokenService implements TokenProvider {
9595
const doOpportunisticRefresh =
9696
!!authProvider.requiresOpportunisticRefresh && authProvider.requiresOpportunisticRefresh();
9797
if (!doOpportunisticRefresh) {
98-
// No opportunistic refresh? Update reserveation and we are done.
98+
// No opportunistic refresh? Update reservation and we are done.
9999
await updateReservation(tokenEntry.uid, token, requestedLifetimeDate);
100100
reportScmTokenRefreshRequest(host, opportunisticRefresh, "still_valid");
101101
return token;

0 commit comments

Comments
 (0)