Skip to content

Support GraphQL over WebSocket authentication via "connect_init" message #268

Closed
@fschmuck

Description

@fschmuck

I implemented my spring-graphql application according to the samples in the repository. The client is a apollo-angular application which receives the jwt from a separate keycloak server. When the client establishes the websocket connection, it sends the jwt in the payload of the connect_init message as described in the graphql-ws documentation.

INIT MESSAGE FROM APOLLO CLIENT: `{"type":"connection_init","payload":{"Authorization":"Bearer <VALID_TOKEN>"}}`
ACK MESSAGE: `{"type":"connection_ack","payload":{}}`
SUBSCRIBE: `{"id":"06b0c701-bf03-4630-a32e-6e3b4da513df","type":"subscribe", <GRAPHQL_SUBSCRIPTION>}`
ERROR: `{"type":"error","payload":[{"message":"An Authentication object was not found in the SecurityContext","locations":[],"extensions":{"classification":"DataFetchingException"}}],"id":"<ID>"}`

The subscription method in the controller is annotated with @PreAuthorize("isAuthenticated()").
I use spring-boot-starter-oauth2-resource-server to validate the jwt against the keyset of the keycloak server.

I do not understand how to validate this jwt and populate the SecurityContext with data. Every sample out there seems to use STOMP endpoints.
Could somebody explain to me how to handle this properly?

Thank you

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions