Repository navigation
Move Link sign-in and token refresh into the SDK - #510
Closed
ksn-stripe wants to merge 2 commits into
Closed
ksn-stripe wants to merge 2 commits into
ksn-stripe wants to merge 2 commits into
Conversation
LinkAuthResource (device authorization, refresh, revocation), the createAccessTokenProvider token-refresh wrapper, scope/authorization-detail helpers, and auth-specific types/errors move from packages/cli/src/auth/ into packages/sdk/src/auth/ and are exported from @stripe/link-sdk, so an app built on the SDK can sign in and keep a token fresh without copying CLI internals (same pattern #489 used for MPP). LinkAuthResource now requires a clientId option instead of a hardcoded constant, so an SDK-based app can't silently pose as link-cli. createAccessTokenProvider now coalesces concurrent refreshes into a single refreshToken call, since Link rotates the refresh token on every use and two parallel refreshes would otherwise race. The CLI keeps its credential storage, pending-device-auth workflow state, auth upgrade merge logic, and login/logout/status commands. Its own auth/session.ts becomes a thin wrapper over the SDK's createAccessTokenProvider that supplies the CLI's exact, unchanged user-facing messages via the new message options. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Committed-By-Agent: claude
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Committed-By-Agent: claude
ksn-stripe
force-pushed
the
ksn/sdk-auth
branch
from
November 4, 2026 15:39
7e506a2 to
4c6bc7d
Compare
raubrey-stripe
requested changes
Nov 4, 2026
raubrey-stripe
left a comment
Contributor
There was a problem hiding this comment.
Hmm I'm not sure we want this/might want to get some context first?
I know @stevekaliski-stripe specifically left auth open / just accepting an access token so that integrating agents would be able to integrate with various OAuth strategies (critically, Muse and other agents don't use device oauth and we don't want them to). @jlau-stripe to confirm as well?
ksn-stripe
marked this pull request as draft
November 4, 2026 20:18
Contributor
Author
|
Tossed up this PR while trying to remove friction from building an agent around the Link SDK. That rationale makes sense for leaving the SDK open for different forms of auth. Closing. |
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.
SDK apps can now sign a user in to Link and keep their token fresh the same way
link-cli auth logindoes. Until now the SDK only acceptedaccessTokenorgetAccessToken, so every SDK agent had to re-implement device sign-in and refresh. The reusable parts oflink-cli's auth code move into@stripe/link-sdk, and the CLI now uses them, the same way #489 did for MPP.New SDK exports
LinkAuthResource: device sign-in (start and poll), refresh, and revoke.clientIdis now a required option, so an SDK app can't silently present itself as the link-cli client. The CLI passes its own ID andclientName: 'Link CLI'; the SDK's default name isLink SDK.createAccessTokenProvider(authResource, storage, options): plugs intonew Link({ getAccessToken }). The app supplies anAuthStorage(getTokens,setTokens,clearTokens).buildAuthorizationDetails, the auth error classes, and the auth types.Behavior change: callers that overlap now share one in-flight refresh. Link replaces the refresh token on every refresh, so two parallel refreshes (common with agents making parallel tool calls) would invalidate the session. The CLI only refreshes from one place, so this doesn't change CLI behavior.
Unchanged in the CLI: its credential file, pending sign-in state,
auth upgrademerge logic, commands, and user-facing messages. A thin wrapper passes the CLI's exact messages to the SDK provider. Refresh at/auth/tokenwith a client secret (registered clients) is out of scope, because the CLI doesn't do it either.Validation: SDK typecheck and tests (375) pass, including the moved auth tests and a new concurrent-refresh test. CLI and Eve typecheck pass, Eve tests pass, and Biome is clean. The full CLI suite runs locally on a rolldown build, because esbuild can't run on my machine: 714 pass, and the 20 that fail are UI rendering tests that fail identically on the base branch. CI runs the real tsup build.
🤖 Generated with Claude Code