diff --git a/.changeset/common-monkeys-take.md b/.changeset/common-monkeys-take.md new file mode 100644 index 0000000..a11a2af --- /dev/null +++ b/.changeset/common-monkeys-take.md @@ -0,0 +1,5 @@ +--- +'@cloudflare/workers-oauth-provider': patch +--- + +Add `getOAuthApi` helper function to access OAuthHelpers outside of the `fetch` method. This enables OAuth functionality in worker RPC methods and other entry points. diff --git a/src/oauth-provider.ts b/src/oauth-provider.ts index 84e6870..b40239c 100644 --- a/src/oauth-provider.ts +++ b/src/oauth-provider.ts @@ -782,6 +782,17 @@ export class OAuthProvider { } } +/** + * Gets OAuthHelpers for the given environment + * @param options - Configuration options for the OAuth provider + * @param env - Cloudflare Worker environment variables + * @returns An instance of OAuthHelpers + */ +export function getOAuthApi(options: OAuthProviderOptions, env: any): OAuthHelpers { + const impl = new OAuthProviderImpl(options); + return impl.createOAuthHelpers(env); +} + /** * Implementation class backing OAuthProvider. * @@ -2272,7 +2283,7 @@ class OAuthProviderImpl { * @param env - Cloudflare Worker environment variables * @returns An instance of OAuthHelpers */ - private createOAuthHelpers(env: any): OAuthHelpers { + public createOAuthHelpers(env: any): OAuthHelpers { return new OAuthHelpersImpl(env, this); }