5656 {"team" , "team:write" },
5757 {"webhook" },
5858 }
59+
60+ scopesApiMap = map [string ]string {
61+ "account:read account:write" : "account:read" ,
62+ "repository:admin repository:write" : "repository:write" ,
63+ "repository:admin" : "repository:admin" ,
64+ "team team:write" : "workspace membership:write (team:write)" ,
65+ "webhook" : "webhook:read and write" ,
66+ }
5967)
6068
6169func NewBitbucketProvider (baseURL string , client * http.Client ) (Provider , error ) {
@@ -107,6 +115,7 @@ func (bb *bitbucket) verifyToken(ctx context.Context, token string, username str
107115 if err != nil {
108116 return fmt .Errorf ("failed checking token scope permission: %w" , err )
109117 }
118+
110119 for _ , requiredScope := range requiredScopes {
111120 isScopeIncluded := false
112121 for _ , scopeOpt := range requiredScope {
@@ -115,7 +124,8 @@ func (bb *bitbucket) verifyToken(ctx context.Context, token string, username str
115124 }
116125 }
117126 if ! isScopeIncluded {
118- return fmt .Errorf ("the provided token is missing required token scopes, got: %s required: %v" , scopes , requiredScopes )
127+ var requestedScopes = bb .getRequestedScopes (requiredScopes )
128+ return fmt .Errorf ("the provided token is missing required token scopes, got: %s \n required: %v" , scopes , requestedScopes )
119129 }
120130 }
121131
@@ -154,3 +164,29 @@ func (bb *bitbucket) request(ctx context.Context, username, token, method, urlPa
154164
155165 return bb .c .Do (req )
156166}
167+
168+ func (bb * bitbucket ) getRequestedScopes (requiredScopes [][]string ) string {
169+ var requestedScopes string = ""
170+
171+ for _ , requiredScopeOpts := range requiredScopes {
172+ var scopeOpts = ""
173+ for _ , requiredScope := range requiredScopeOpts {
174+ if len (scopeOpts ) > 0 {
175+ scopeOpts += " "
176+ }
177+ scopeOpts += requiredScope
178+ }
179+
180+ if len (requestedScopes ) > 0 {
181+ requestedScopes += ", "
182+ }
183+
184+ if len (scopesApiMap [scopeOpts ]) > 0 {
185+ requestedScopes += scopesApiMap [scopeOpts ]
186+ } else {
187+ requestedScopes += scopeOpts
188+ }
189+ }
190+
191+ return requestedScopes
192+ }
0 commit comments