Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance: Support slack bot token #1788

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -430,12 +436,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 @@ -225,6 +225,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