User OAuth tokens and profiles are stored globally instead of being scoped per instance
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript
- Domain
- authentication
Research direction
Start with the OAuth connect and completion flow in server/api.go, then trace the user profile and token storage and lookup functions named in server/plugin.go. Check how the state identifies the instance and how callers retrieve credentials. Done means credentials and profiles can be stored and retrieved independently per instance, with legacy keys still readable for migration.
Written by the indexing model from the issue text.
Description
Summary
User OAuth credentials and profile metadata are stored in the KV store keyed only by the Mattermost userID (<userID>_userinfo and <userID>_gitlabtoken). This prevents users from connecting to more than one GitLab instance and causes immediate token invalidation when switching the default instance.
Steps to Reproduce
- Mattermost has two GitLab instances configured.
- User connects to Instance A via
/gitlab connect. - User attempts to connect to or interact with Instance B.
- Result: Connecting to Instance B completely overwrites the stored OAuth token and user profile from Instance A.
- If an administrator sets Instance B as default, all existing users' tokens remain mapped to Instance A's authority, causing all subsequent API operations to fail with
401 Unauthorized.
Expected Behavior
Users should be able to authenticate with multiple configured GitLab instances independently, with their session tokens stored under instance-scoped keys.
Root Cause / Code References
server/plugin.go:storeGitlabUserInfowrites toinfo.UserID + GitlabUserInfoKey(_userinfo) andstoreGitlabUserTokenwrites touserID + GitlabTokenKey(_gitlabtoken).server/plugin.go:getGitlabUserInfoByMattermostIDandgetGitlabUserTokenByMattermostIDretrieve credentials using onlyuserID.server/api.go: OAuth state parameter is formatted asmodel.NewId()[0:15] + "_" + userIDwithout any instance identifier, preventing/oauth/completefrom knowing which instance issued the authorization code.
Proposed Fix
- Include target
instanceNamein the OAuth state token during/oauth/connect. - Namespace user KV storage keys by instance name:
<userID>_<instanceName>_userinfoand<userID>_<instanceName>_gitlabtoken. - Provide a fallback reader to lazily migrate legacy un-namespaced keys for existing installations.
- Dominant language
- JavaScript
- Stars
- 158
- Forks
- 97
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 21
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mattermost/mattermost-plugin-gitlab
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
mattermost/mattermost-plugin-gitlab#746 ·
Maintainers usually reply within 2 days
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
mattermost/mattermost-plugin-gitlab#737 ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 1-2 days Newbie friendliness 53/100
mattermost/mattermost-plugin-gitlab#736 ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
mattermost/mattermost-plugin-gitlab#668 · 1 comment · 2 reactions ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
mattermost/mattermost-plugin-gitlab#616 ·
Maintainers usually reply within 2 days
All issues in mattermost/mattermost-plugin-gitlab
Similar issues
-
Difficulty 1/5 1-3 hours Newbie friendliness 82/100
NYCPlanning/labs-applicant-portal#1393 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Trust-Analysis/Tokenized-Fractional-#1115 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
LadybirdBrowser/ladybird#15164 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Konfirm-xyz/konfirm-frontend#318 ·
Maintainers usually reply within 1 day
-
AI effort: [XS] priority: medium severity: minor type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day