-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Subscription Authorization cannot be retrieved from payload (payload is empty) #691
Comments
You must also pass your auth in the WS payload. e.g. with Apollo WS-Link auth.
I hope that helps you! |
@JulienBreux Yep I have done the exact same thing for my client side. And I still cannot get anything there. |
I believe I have found a way to make this work : I used the fourth option of subscription-transport-ws SubscriptionClient (it's a straight pass through from WebSocketLink in the example above) that undocumented option lets me tweak the Sec-Websocket-Protocol header, which is really the only header I can set. as described by this answer : https://stackoverflow.com/a/35108078/118755 the code looks like this :
I had to replace the spaces by "+" in the token otherwise I would get errors. All I have to do on the Go server side is remove the "graphql-ws, " first found in the header and break the auth header with "+" instead of spaces but everything else is the same as checking my Authorization header. The "graphql-ws" will be returned by the ws upgrader which is the preferred protocol that we've indicated. I believe the alternative (probably less hacky!) is to create a new endpoint in your Go mux router specifically for websockets and perform the Auth not at the header levels but in the first packet at the application level. The connectionParams will get sent once the connection is established, but you need to upgrade the connection and return a 200 first. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
What happened?
This is my handler setting below:
h := handler.GraphQL(Application.NewExecutableSchema(Application.Config{Resolvers: &Application.Resolver{}}),handler.WebsocketUpgrader(websocket.Upgrader{CheckOrigin: func(r *http.Request) bool {return true}}))
Inside of my myBearerAuthMiddleWare, I am checking the context of gin and using GetInitPayload function to get the payload of Websocket request. However, the payload is empty.
payload = handler.GetInitPayload(myContext)
What did you expect?
I expect that the payload is not empty and with payload.Authorization() I can get the bearer token passed by from the client side.
Minimal graphql.schema and models to reproduce
versions
gqlgen version
? 0.8.3go version
? go1.12 darwin/amd64The text was updated successfully, but these errors were encountered: