Repository navigation
feat(auth): keep one OAuth login per organization and route by directory - #151
Open
ishaanxgupta wants to merge 2 commits into
Open
ishaanxgupta wants to merge 2 commits into
ishaanxgupta wants to merge 2 commits into
Conversation
ishaanxgupta
marked this pull request as ready for review
October 25, 2026 13:19
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.
Stacked on #121.
Why
With #121 the plugin holds one OAuth login, and a login is for one organization (the token's
organization_id). Logging in again to add a second org overwrites the first, and every directory uses whichever org you logged in to last. There's no way to keep a company repo on the company org and everything else on personal.What changes
One login per organization in this plugin's own file; the folder picks which one.
~/.supermemory-claude/credentials.jsonbecomes v2:{ ...registration, defaultOrganization, organizations: { [orgId]: { accessToken, refreshToken, expiresAt } } }. The v1 file from feat: authenticate Claude plugin with OAuth DCR and PKCE #121 is read under the org its token names and rewritten as v2 on the next save. A token without that claim is dropped and the user logs in again, rather than its memories landing in a guessed org.prompt=consentalready forces it). The first org becomes the default, and a later login never takes it.getAuthToken(cwd)asksrouteOrganizationfor the directory's org, using the shared rules in~/.supermemory/config.json, the repo's committed.supermemory/config.json,SUPERMEMORY_ORGand the default. It then uses that org's token. The hooks and the MCP proxy all go through it. Env/project API keys keep precedence, unchanged.getAuthTokenthrowsORG_PAUSED:paused.invalid_grantremoves only that org's login;invalid_clientdrops all tokens and the registration, as before.fetch. A 401 on a token refreshed less than 2 minutes ago marks the org rejected, which pauses it. An older token is just expired and refreshes on the next call. This stops the endless refresh loop after you're removed from an org.auth.js login(adds an org),status(orgs without secrets),use <org>,logout [--org <id>](revokes one org or all).scripts/build-agent-config.mjsvendors the mono package intoplugin/hooks/vendor/agent-config.cjs, the same way the SDK is vendored.