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

How can i pass credentials (cookies) to networkLayer ? #1

Closed
filod opened this issue Nov 16, 2015 · 7 comments
Closed

How can i pass credentials (cookies) to networkLayer ? #1

filod opened this issue Nov 16, 2015 · 7 comments
Labels

Comments

@filod
Copy link

filod commented Nov 16, 2015

have to wait facebook/relay#558 ?

@denvned
Copy link
Owner

denvned commented Nov 16, 2015

Yes, I think it is currently impossible to pass user specific cookies to a network layer on the server. But, you can pass the credentials to your HTTP server in a cookie as usual, then pass them to the GraphQL server as an ID parameter of the query root field.

@filod
Copy link
Author

filod commented Nov 30, 2015

But how can i pass params to GraphQL ? intercept query from client then change it manually ? sounds too tricky...

@denvned
Copy link
Owner

denvned commented Nov 30, 2015

No, you don't have to intercept any GraphQL queries from the client. The client can set query params including the user ID, itself.

When receiving request from a client, the GraphQL server can verify that the user ID, passed as a query param, match the user credentials, passed in HttpOnly cookies. The GraphQL server verifies only client requests because the server can't send user specific cookies (the singleton network layer does not allow it), but the GraphQL server trusts requests from the server anyway, so that is not a problem.

I know, all this is too complicated anyway, but at least it do the job.

@filod
Copy link
Author

filod commented Dec 1, 2015

you mean send queries both in client & server like:

viewer(uid: xxxxx) { 
  nickname
}

seems i can only pass it as a url query param ( with react-router-relay use prepareParams), but i need auth user in every root queries' resolve function except query from server... but it's really too complicated...

@filod filod closed this as completed Dec 1, 2015
@denvned
Copy link
Owner

denvned commented Dec 1, 2015

seems i can only pass it as a url query param

You can pass it as a state param.

but i need auth user in every root queries' resolve function except query from server... but it's really too complicated...

The GraphQL server should authenticate and authorize users anyway, even without isomorphism. And it is not so hard to detect that query came from the server. In that case only authorization is needed, and authentication could be just skipped.

@filod
Copy link
Author

filod commented Dec 1, 2015

Yep, i use passport as authorization solution. seems no open source solution that can mix them up, so, a lot of work to do.

anyway, thx very much for your help!

@thelordoftheboards
Copy link

@denvned Is there anywhere an example of implementing your idea:

When receiving request from a client, the GraphQL server can verify that the user ID, passed as a query param, match the user credentials, passed in HttpOnly cookies. The GraphQL server verifies only client requests because the server can't send user specific cookies (the singleton network layer does not allow it), but the GraphQL server trusts requests from the server anyway, so that is not a problem.

Or possibly different examples implementing different parts of it? I am fairly new to this and while I understand it on the conceptual level, it is hard for me to tell how to implement all the pieces.

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

No branches or pull requests

3 participants