-
Notifications
You must be signed in to change notification settings - Fork 107
Add getOAuthHelpers method #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…e of a fetch call
|
|
@mattzcarey - Can you give this a review? @kentonv - Found a neat way to add methods to the provider without exposing them over RPC |
src/oauth-provider.ts
Outdated
| /** | ||
| * Gets OAuthHelpers for the given environment, setting env.OAUTH_PROVIDER if not already set | ||
| * This is a getter property that returns a function, allowing it to be accessed like a normal class member | ||
| * without being exposed as an RPC method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hate to say but getters can, in fact, be invoked over RPC. It's an explicit feature of the RPC system.
You could perhaps create a separate freestanding function getOAuthHelpers(provider :OAuthProvider), and this function could work by reading a property whose name is a private Symbol.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh thought I was being clever here. Must have messed something up when testing.
Switched it over to a Symbol and getOAuthHelpers(provider: OAuthProvider, env: any) method. Confirmed this is working as expected. Thanks!
This PR makes OAuthHelpers available outside of the
fetchmethod (i.e. in a worker's RPC methods).Problem
this.env.OAUTH_PROVIDERgets populated inOAuthProviderImpl.fetch(), so if we try to use it in a worker's RPC methods, for example, it will always be undefined.Solution
We need a method
OAuthProvider.getOAuthHelpers(env: any)that initializes and retrieves OAuthHelpers directly from the provider.❌ We can't put the method directly onto the provider because it will get exposed, intentionally or otherwise, as a public RPC method on the worker.
✅ But if we use a Symbol to name the method, it appears on the provider like we want, but excluded from the worker's RPC methods.