'Authenticating Apollo Websocket subscription with nginx/lua
Trying out Hasura with an Apollo client, and followed documentation for adding authTokens: https://www.apollographql.com/docs/react/data/subscriptions/
import { GraphQLWsLink } from '@apollo/client/link/subscriptions';
import { createClient } from 'graphql-ws';
const wsLink = new GraphQLWsLink(createClient({
url:url,
connectionParams: {
authToken: user.authToken,
},
}));
My url goes to a nginx reverse proxy setup, which looks like something like this:
location /ws {
proxy_pass http://wsbackend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
At this point, I'm a little lost on how to have my JWT Token that exists in the first connection request get authenticated here? I have to somehow gain access to the connection request payload? My other regular http requests get authenticated with Authorization in the header through a LUA script(access_by_lua_file).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
