fix(discord): always include identify scope (#414)#642
Open
yabanci wants to merge 1 commit into
Open
Conversation
The discord provider's newConfig dropped ScopeIdentify whenever the caller passed any custom scope. Discord's /users/@me endpoint requires the identify scope -- other scopes (email, connections, guilds) only enrich the response, they don't grant access on their own. So callers that requested e.g. just 'email' got a 401 from FetchUser. Always include ScopeIdentify in the OAuth2 scope list and skip it when appending user-supplied scopes to avoid duplicating it. Added a table-driven regression test covering: no scopes, email-only, explicit identify (no dupe), and multiple custom scopes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Closes #414.
providers/discord/discord.go:newConfigcurrently dropsScopeIdentifywhenever the caller passes any custom scope:So calling
discord.New(k, s, cb, "email")yieldsScopes: ["email"], which Discord rejects with401from/users/@me. The reporter (@tardisx) hit this exact path.Discord's docs are explicit:
identifyis the scope that gates/users/@meitself;emailonly enriches the response. The existing constant in this file even spells it out:Change
Always include
ScopeIdentifyfirst, then append user scopes while filtering out a duplicateidentify:Backward compatibility
[identify].[identify, ...]: unchanged — order preserved, no duplication.identify(e.g.[email]): now[identify, email]instead of[email]. Their previously-brokenFetchUsercall now succeeds. The only behavioural difference is that Discord's consent screen will listidentify— which is correct, since the app was already trying to read user info.Tests
Added
Test_DefaultScopeAlwaysIncludesIdentify— table-driven, four cases:config.Scopesnil[identify][email][identify, email][identify, email][identify, email][email, connections, guilds][identify, email, connections, guilds]Verified the new test fails on master (cases 2 and 4 explicitly miss
identify) and passes with the fix applied.go test ./...is green across all 50+ providers;go vet ./...is clean.