Skip to content

Conversation

@IfDougelseSa
Copy link

Description

Fixes plugin notifications for SSO-authenticated users by querying the SSO provider's external_id instead of using the notification plugin's name.

Problem

Plugin notifications were failing for users authenticated via SSO (GitHub OAuth, Google, SAML, etc.) because the code was looking up external_id using the notification plugin's name instead of the SSO authentication provider.

Example:

  • User logs in via provider = "github" (SSO)
  • Code searches for provider = "discord" (notification plugin)
  • No match found → ReceiverExternalID is empty

Solution

Query all external logins for the user and use the most recent one (ORDER BY updated_at DESC).

Changes

  • Add ORDER BY updated_at DESC to GetUserExternalLoginList
  • Update notification code to query all external logins
  • Use first login from ordered list (most recent)

Testing

Before:
Receiver External ID: ← Empty

After:
Receiver External ID: 81540136 ← Populated

Tested with GitHub OAuth SSO and test notification plugin.

@LinkinStars
Copy link
Member

@IfDougelseSa Originally, this notification plugin was designed to provide consistent notification functionality when users log in with the same account. For example, logging in with Slack would trigger corresponding Slack notifications. Of course, the scenario you mentioned is indeed an issue—users can configure different login methods and notification channels.

Therefore, our recommendation is to retain both query methods. By default, it will use externalLogins[0].ExternalID, but it will also retain the query via fn.Info().SlugName. This way, if plugins for the same external system exist, notifications from that specific external system will take precedence.

Comment on lines -427 to -434
userInfo, exist, err := ns.userExternalLoginRepo.GetByUserID(ctx, fn.Info().SlugName, msg.ReceiverUserID)
if err != nil {
log.Errorf("get user external login info failed: %v", err)
return nil
}
if exist {
pluginNotificationMsg.ReceiverExternalID = userInfo.ExternalID
}
Copy link
Member

@LinkinStars LinkinStars Dec 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can retain this section so that if a search is available, notifications from the same system can be prioritized. If no match is found, the default externalLogins[0].ExternalID will be used.

}
}

userInfo, exist, err := ns.userExternalLoginRepo.GetByUserID(ctx, fn.Info().SlugName, subscriberUserID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can retain this section so that if a search is available, notifications from the same system can be prioritized.

@LinkinStars LinkinStars self-assigned this Dec 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants