-
Notifications
You must be signed in to change notification settings - Fork 341
authorizing subscriptions -- set a default context for client #75
Comments
I think this is solved by |
Nope, I don't think it solves the challenge but please correct me if I'm wrong. As I understand it: @NeoPhi suggested in #78 that we could have a |
@srtucker22 I am not sure if this was intended as such, but I found out that returning an object from Also note that the context is also passed to Edit: Oh sorry, I think I misread your message. I don't quite understand how using the connectionParams would be problematic, though? If you wanted to pass auth information on a per-subscription basis it makes sense (and you can do that), but if you want to do it automatically for all subscriptions then you might as well pass that info on connection? |
yeah, i'm just focussed on client side setting/updating context per call or for every call. an example: you could pass context into every we should just change |
UPDATE: @srtucker22 sorry to resurrect this issue if you got it resolved. Wondering if you could share your findings. I'm trying to achieve the same auth functionality where I need to modify the context passed into the onConnect. My scenario is that a user should be able to subscribe (passing the auth token in After the user logs out, I need to allow the user to login as a different user with a different token. I see two ways to achieve this:
Do you have any insight into what's the best method to achieve subscription authorization and manage changing |
@swhamilton no worries! You're absolutely correct that those are your two main options. Option 1: Server: shameless plug You can check out the subscription section of my blog post on GraphQL Authorization for an example of how this looks on the server and client. Option 2: Client:
This middleware will run before each subscription call. Server: Let me know if that helps! |
@srtucker22 wow great summary. Thanks for the insight and blog post - all of it was very helpful! I was able to get it working finally with a reset websocket function implemented here: but I do want to try the middleware strategy for future use. |
My goal is simply to validate whether a user is authorized to subscribe to a given channel. For example, if I was creating a group chat app, only members of a group would be able to subscribe to
onMessageAdded(groupId: Int!)
for that groupId.From my understanding from digging into the code...
On the server, I can accomplish allowing/denying subscriptions via onSubscribe with a given context:
On the client, I'm trying to figure out a way to set up a default context for all subscriptions, similar to how
networkInterface
exposes this with middleware. For example, usingnetworkInterface
, we have a redux store that sets a jwt token on authorization headers. We send out queries with auth headers if the jwt is set, and on the server side, we validate the jwt token and pass the validated user intocontext
for the resolvers to consume.I'd imagine something similar would/should be possible with SubscriptionManager, where we either (1) apply context via a setupFunction using
next
or a Promise, or (2) expose some public function that updates the default context for all subscriptions. This seems particularly important if we're usingsubscribeToMore
as I don't see an obvious way to pass context with this call.Any help or suggestions appreciated!
The text was updated successfully, but these errors were encountered: