Add support for SDK to use OAuth2.0 PKCE flow#13804
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 71d4905 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds OAuth2 PKCE support to the @audius/sdk browser OAuth flow by introducing PKCE helpers, an in-memory token store, and a middleware that auto-refreshes tokens on 401s, while also shifting API-key-only SDK construction to the API-forward (no-services) SDK path.
Changes:
- Add PKCE utility functions + an
OAuthTokenStoreand export them fromsdk/oauth. - Extend
OAuthto support PKCE code exchange, token refresh, and logout flows. - Add
addTokenRefreshMiddlewareto transparently refresh + retry requests after 401s, and wire it intocreateSdkWithoutServices.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/sdk/src/sdk/sdk.ts | Routes API-key-only configs to createSdkWithoutServices (API-forward SDK type). |
| packages/sdk/src/sdk/oauth/tokenStore.ts | Adds an in-memory token store with a Configuration.accessToken provider. |
| packages/sdk/src/sdk/oauth/tokenStore.test.ts | Unit tests for token store behavior. |
| packages/sdk/src/sdk/oauth/pkce.ts | Adds PKCE verifier/challenge/state helpers. |
| packages/sdk/src/sdk/oauth/pkce.test.ts | Tests PKCE helpers including RFC 7636 test vector. |
| packages/sdk/src/sdk/oauth/index.ts | Re-exports PKCE + token store helpers. |
| packages/sdk/src/sdk/oauth/OAuth.ts | Implements PKCE login + code exchange, token refresh, and logout support. |
| packages/sdk/src/sdk/middleware/index.ts | Exports the new token refresh middleware. |
| packages/sdk/src/sdk/middleware/addTokenRefreshMiddleware.ts | Adds 401-handling refresh + retry middleware. |
| packages/sdk/src/sdk/middleware/addTokenRefreshMiddleware.test.ts | Tests refresh + retry and failure modes. |
| packages/sdk/src/sdk/createSdkWithoutServices.ts | Wires in token store + refresh middleware; exposes tokenStore on returned SDK. |
| .changeset/breezy-lions-jog.md | Declares a minor release for PKCE/refresh token support. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…on-service sdk init
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…middleware (#13805) Removes the deps on usersApi by removing the `isWriteAccessGranted` method (which is redundant to the devApps APIs) and the `verifyToken` method (which is redundant with the usersApi) and calling fetch manually internally. Then, this allows the OAuth service to be initialized before other APIs so that it can be used in the config for middlewares to all other APIs. --------- Co-authored-by: Dylan Jeffers <dylan@audius.co> Co-authored-by: Ray Jacobson <ray@audius.co> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
8a8dd59 to
a745e43
Compare
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.
Adds helpers + refresh middleware and updates OAuth service to support PKCE flow.
Makes API key only configs use the API-forward SDK type