Skip to content

Commit d7ef12b

Browse files
authored
Enhance: Support slack bot token (#1788)
Signed-off-by: Daishan Peng <[email protected]>
1 parent d25b09d commit d7ef12b

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

pkg/gateway/server/oauth_apps.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,13 @@ func (s *Server) authorizeOAuthApp(apiContext api.Context) error {
266266
// Slack is annoying and makes us call this query parameter user_scope instead of scope.
267267
// user_scope is used for delegated user permissions (which is what we want), while just scope is used for bot permissions.
268268
if app.Spec.Manifest.Type == types2.OAuthAppTypeSlack {
269-
q.Set("user_scope", scope)
269+
if scope != "" {
270+
q.Set("scope", scope)
271+
}
272+
userScope := apiContext.URL.Query().Get("user_scope")
273+
if userScope != "" {
274+
q.Set("user_scope", userScope)
275+
}
270276
} else {
271277
q.Set("scope", scope)
272278
}
@@ -431,12 +437,18 @@ func (s *Server) callbackOAuthApp(apiContext api.Context) error {
431437
}
432438

433439
tokenResp = &types.OAuthTokenResponse{
434-
State: state,
435-
Scope: slackTokenResp.AuthedUser.Scope,
436-
AccessToken: slackTokenResp.AuthedUser.AccessToken,
437-
Ok: slackTokenResp.Ok,
438-
Error: slackTokenResp.Error,
439-
CreatedAt: time.Now(),
440+
State: state,
441+
Ok: slackTokenResp.Ok,
442+
Error: slackTokenResp.Error,
443+
CreatedAt: time.Now(),
444+
}
445+
446+
if slackTokenResp.AuthedUser.AccessToken != "" {
447+
tokenResp.AccessToken = slackTokenResp.AuthedUser.AccessToken
448+
tokenResp.Scope = slackTokenResp.AuthedUser.Scope
449+
} else if slackTokenResp.AccessToken != "" {
450+
tokenResp.AccessToken = slackTokenResp.AccessToken
451+
tokenResp.Scope = slackTokenResp.Scope
440452
}
441453
case types2.OAuthAppTypeGitHub:
442454
// Read the response body

pkg/gateway/types/oauth_apps.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ type SlackOAuthTokenResponse struct {
231231
Scope string `json:"scope"`
232232
AccessToken string `json:"access_token"`
233233
} `json:"authed_user"`
234+
AccessToken string `json:"access_token"`
235+
Scope string `json:"scope"`
234236
}
235237

236238
type OAuthTokenRequestChallenge struct {

0 commit comments

Comments
 (0)