Pass WS initial payload from gateway to federated services
Hi, for my use case it's required to pass user related information (token/id/roles) from gateway to federated services. There are two possible options:
- Use payload in
connection_initmessage (receiver must handle initPayload fromconnection_initmessage) (I prefer this option) - Use
Headerfield fromFetchConfiguration(receiver must handle http header (before upgrading))
Both options aren't ready to use, they require some contribution.
@jensneuse which option would you prefer ?
Can you expand a bit on option 1)? How will it work? I think I'd like to have a generic solution that allows users (like you) to find their own ways of using the library. So I'm preferring to keep things generic.
@jensneuse I checked all my cases, and it turned out that in all cases ws initial payload is almost exactly the same as Header for the same upstream.
In my fork, I just added sending Header as ws initial Payload. If necessary, I can create a PR, otherwise theissue can be closed.
I'm not sure I understand 100%. How would Header as ws initial payload look like?
I'm not sure I understand 100%. How would Header as ws initial payload look like?
According to gqlgen interface, designed to handle WS auth https://gqlgen.com/recipes/authentication/#websockets, it expects type InitPayload map[string]interface{} (https://github.com/99designs/gqlgen/blob/master/graphql/handler/transport/websocket_init.go) and provides safe getters for strings (defaulting to "", same as http.Header, but with after type-checking for string.
I've checked how Playground works also, it sends {"type":"connection_init","payload":{"Authorization":"test"}} if you define some headers at the bottom.
Apollo Link has connectionParams option and also sends it as payload. (https://www.apollographql.com/docs/react/data/subscriptions/#5-authenticate-over-websocket-optional)
import { WebSocketLink } from '@apollo/client/link/ws';
const wsLink = new WebSocketLink({
uri: 'ws://localhost:4000/subscriptions',
options: {
reconnect: true,
connectionParams: {
authToken: user.authToken,
},
},
});
closed with https://github.com/wundergraph/graphql-go-tools/pull/425