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

🦋 Changeset detected

Latest commit: 97b1e1e

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

This PR includes changesets to release 1 package
Name Type
@cloudflare/workers-oauth-provider 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

@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
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 8, 2026

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/workers-oauth-provider/@cloudflare/workers-oauth-provider@117

commit: 97b1e1e

@mattzcarey mattzcarey merged commit b2c5877 into cloudflare:main Jan 8, 2026
4 checks passed
@github-actions github-actions bot mentioned this pull request Jan 8, 2026
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.

3 participants