fix(connector): relax Slack incoming webhook requirement

ParseSlackTokenResponse treated the incoming_webhook field as
mandatory, which blocked any Slack OAuth2 flow that did not request
the incoming-webhook scope. Access review Slack connects only ask
for users:read and users:read.email and would fail at token parsing.

Treat incoming_webhook as optional: populate SlackSettings when it
is present, leave them empty otherwise. The existing compliance-page
webhook URL is preserved through Reconnect in a later commit.

Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
This commit is contained in:
Aurélien Sibiril
2026-04-09 01:02:18 +02:00
parent d0fedcf39e
commit 62bab0f732
2 changed files with 73 additions and 11 deletions

View File

@@ -111,20 +111,15 @@ func (c *SlackConnection) UnmarshalJSON(data []byte) error {
func ParseSlackTokenResponse(body []byte, oauth2Conn OAuth2Connection, organizationID gid.GID) (*SlackConnection, *gid.GID, error) {
var slackResponse SlackTokenResponse
var buf bytes.Buffer
buf.Write(body)
if err := json.NewDecoder(&buf).Decode(&slackResponse); err != nil {
if err := json.NewDecoder(bytes.NewReader(body)).Decode(&slackResponse); err != nil {
return nil, nil, fmt.Errorf("cannot decode Slack token response: %w", err)
}
if slackResponse.IncomingWebhook == nil {
return nil, nil, fmt.Errorf("incoming webhook is required for Slack")
}
settings := SlackSettings{
WebhookURL: slackResponse.IncomingWebhook.URL,
Channel: slackResponse.IncomingWebhook.Channel,
ChannelID: slackResponse.IncomingWebhook.ChannelID,
settings := SlackSettings{}
if slackResponse.IncomingWebhook != nil {
settings.WebhookURL = slackResponse.IncomingWebhook.URL
settings.Channel = slackResponse.IncomingWebhook.Channel
settings.ChannelID = slackResponse.IncomingWebhook.ChannelID
}
return &SlackConnection{