Skip to content

Conversation

@DeanMauro
Copy link
Contributor

@DeanMauro DeanMauro commented Dec 12, 2025

This PR makes OAuthHelpers available outside of the fetch method (i.e. in a worker's RPC methods) via the getOAuthApi function.

Problem

this.env.OAUTH_PROVIDER gets populated in OAuthProviderImpl.fetch(), so if we try to use it in a worker's RPC methods, for example, it will always be undefined.

const providerOptions = {...};

// Create the OAuth provider instance
const oauthProvider = new OAuthProvider(providerOptions);

export default class extends WorkerEntrypoint<AuthWorkerEnv> {
  async fetch(request: Request) {...}

  async checkClient(id: string) {
    // ERROR because this.env.OAUTH_PROVIDER isn't set yet
    const existingClient = await this.env.OAUTH_PROVIDER.lookupClient(id);

    // SUCCESS
    const existingClient = await getOAuthApi(providerOptions, this.env).lookupClient(id);
  }
}

Solution

We add a method getOAuthApi(options: OAuthProviderOptions, env: any) that initializes and retrieves OAuthHelpers directly.

@changeset-bot
Copy link

changeset-bot bot commented Dec 12, 2025

⚠️ No Changeset found

Latest commit: a210ce5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@DeanMauro
Copy link
Contributor Author

@mattzcarey - Can you give this a review?

@kentonv - Found a neat way to add methods to the provider without exposing them over RPC

@DeanMauro DeanMauro requested a review from kentonv December 13, 2025 03:02
@DeanMauro DeanMauro requested a review from kentonv December 27, 2025 03:58
@DeanMauro
Copy link
Contributor Author

@kentonv Updated with requested changes.
cc @mattzcarey

@DeanMauro DeanMauro changed the title Add getOAuthHelpers method Add getOAuthApi method Dec 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants