Skip to content
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

Header is not set for subscription #416

Closed
bsr203 opened this issue Oct 9, 2018 · 12 comments
Closed

Header is not set for subscription #416

bsr203 opened this issue Oct 9, 2018 · 12 comments

Comments

@bsr203
Copy link

bsr203 commented Oct 9, 2018

Hi.
I set the header through set headers, and I could see that it is set for graphql query, mutations (POST request). But, with the same session/window, if I try a subscription request, header is not set. If I don't validate the request at server (don't check Auth header), then everything works. That indicates, subscription query from altair is fine except no header set (as i also see through chrome dev tools panel)

thanks.
bsr.

@welcome
Copy link

welcome bot commented Oct 9, 2018

👋🏾Thanks for opening your first issue here! Be sure to follow the issue template! ✌🏾

@imolorhe
Copy link
Collaborator

Thanks for reporting this! I'd look into it as soon as I can.

@0xdevalias
Copy link

0xdevalias commented Oct 11, 2018

Just hit this issue myself trying to subscribe to an AWS AppSync API protected with an API_KEY (sent in x-api-key header).

Was hoping that Altair would handle it, as graphql-playground couldn't either.

It appears the underlying websocket connections are handled by subscriptions-transport-ws, googling for that and http headers lead me to the following:

AWS's AppSync doco suggests that it can use the Apollo client, but they provide custom plugins to handle auth/subscription handshakes:

Looking at the custom apollo links implemented in the AppSync SDK we can see that they implement their own header based auth functionality (i'm assuming this also applies to the websocket part.. but not 100%):

So perhaps a similar approach could be leveraged here?

Looking further at the subscription handshake link, it seems that AppSync implements MQTT over the websocket.. so it may not work properly here anyway (opened new issue for this: #417):

@imolorhe
Copy link
Collaborator

@0xdevalias Thanks for the contextual information.

@imolorhe
Copy link
Collaborator

@bsr203 How are you using subscriptions with headers?

@bsr203
Copy link
Author

bsr203 commented Oct 11, 2018

I have a server (golang) app running on google cloud. So, I was using go standard http package to extract the header, just like POST/ GET request.
I don't know server matters, as the initial ws upgrade POST request from altair doesn't have the header, and I assume it should be like any other POST request.

@imolorhe
Copy link
Collaborator

@bsr203 From the conversation here, https://github.com/apollographql/graphql-subscriptions/blob/master/.designs/authorization.md, It appears you can't set the header in the initial request. Unless I'm missing something.

@bsr203
Copy link
Author

bsr203 commented Oct 11, 2018

@imolorhe thanks for the link. Sorry that I guessed it should work with initial POST request. I will look into any of the option which can be implemented outside the HTTP header can be done in my case. thanks again.

@0xdevalias
Copy link

0xdevalias commented Oct 11, 2018 via email

@imolorhe
Copy link
Collaborator

@0xdevalias I'm concerned about implementing this if there is no standard (or near standard) way of handling the authentication. It seems the authentication is handled differently as decided by the developers and the authentication mechanism available to them. If this were to be implemented, what exactly would need to be implemented?

@0xdevalias
Copy link

0xdevalias commented Oct 12, 2018 via email

@imolorhe
Copy link
Collaborator

imolorhe commented Dec 1, 2018

Implementing this with the approach defined by apollo graphql subscriptions for the SubscriptionServer, using the onConnect callback to validate the subscription connection request as implemented here.

This is one of a number of approaches used by various libraries but this has the best chance of being the de-facto approach for authentication across GraphQL websocket subscriptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants