Skip to content

Add support for SDK to use OAuth2.0 PKCE flow#13804

Merged
rickyrombo merged 7 commits into
mainfrom
mjp-oauth-net-new
Mar 9, 2026
Merged

Add support for SDK to use OAuth2.0 PKCE flow#13804
rickyrombo merged 7 commits into
mainfrom
mjp-oauth-net-new

Conversation

@rickyrombo
Copy link
Copy Markdown
Contributor

Adds helpers + refresh middleware and updates OAuth service to support PKCE flow.

Makes API key only configs use the API-forward SDK type

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 4, 2026

🦋 Changeset detected

Latest commit: 71d4905

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@audius/sdk Minor
@audius/sdk-legacy Patch
@audius/sp-actions Patch

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 OAuthTokenStore and export them from sdk/oauth.
  • Extend OAuth to support PKCE code exchange, token refresh, and logout flows.
  • Add addTokenRefreshMiddleware to transparently refresh + retry requests after 401s, and wire it into createSdkWithoutServices.

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.

Comment thread packages/sdk/src/sdk/oauth/OAuth.ts
Comment thread packages/sdk/src/sdk/oauth/OAuth.ts
Comment thread packages/sdk/src/sdk/oauth/OAuth.ts Outdated
Comment thread packages/sdk/src/sdk/middleware/addTokenRefreshMiddleware.ts
Comment thread packages/sdk/src/sdk/oauth/pkce.ts Outdated
rickyrombo and others added 6 commits March 9, 2026 12:05
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>
@rickyrombo rickyrombo merged commit 0cbaf44 into main Mar 9, 2026
5 checks passed
@rickyrombo rickyrombo deleted the mjp-oauth-net-new branch March 9, 2026 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants