Skip to content

Commit

Permalink
Enhance: Support slack bot token (#1788)
Browse files Browse the repository at this point in the history
Signed-off-by: Daishan Peng <[email protected]>
  • Loading branch information
StrongMonkey authored Feb 20, 2025
1 parent d25b09d commit d7ef12b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
26 changes: 19 additions & 7 deletions pkg/gateway/server/oauth_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,13 @@ func (s *Server) authorizeOAuthApp(apiContext api.Context) error {
// Slack is annoying and makes us call this query parameter user_scope instead of scope.
// user_scope is used for delegated user permissions (which is what we want), while just scope is used for bot permissions.
if app.Spec.Manifest.Type == types2.OAuthAppTypeSlack {
q.Set("user_scope", scope)
if scope != "" {
q.Set("scope", scope)
}
userScope := apiContext.URL.Query().Get("user_scope")
if userScope != "" {
q.Set("user_scope", userScope)
}
} else {
q.Set("scope", scope)
}
Expand Down Expand Up @@ -431,12 +437,18 @@ func (s *Server) callbackOAuthApp(apiContext api.Context) error {
}

tokenResp = &types.OAuthTokenResponse{
State: state,
Scope: slackTokenResp.AuthedUser.Scope,
AccessToken: slackTokenResp.AuthedUser.AccessToken,
Ok: slackTokenResp.Ok,
Error: slackTokenResp.Error,
CreatedAt: time.Now(),
State: state,
Ok: slackTokenResp.Ok,
Error: slackTokenResp.Error,
CreatedAt: time.Now(),
}

if slackTokenResp.AuthedUser.AccessToken != "" {
tokenResp.AccessToken = slackTokenResp.AuthedUser.AccessToken
tokenResp.Scope = slackTokenResp.AuthedUser.Scope
} else if slackTokenResp.AccessToken != "" {
tokenResp.AccessToken = slackTokenResp.AccessToken
tokenResp.Scope = slackTokenResp.Scope
}
case types2.OAuthAppTypeGitHub:
// Read the response body
Expand Down
2 changes: 2 additions & 0 deletions pkg/gateway/types/oauth_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ type SlackOAuthTokenResponse struct {
Scope string `json:"scope"`
AccessToken string `json:"access_token"`
} `json:"authed_user"`
AccessToken string `json:"access_token"`
Scope string `json:"scope"`
}

type OAuthTokenRequestChallenge struct {
Expand Down

0 comments on commit d7ef12b

Please sign in to comment.