How to send Request's `id_token` cookie in npm-fetch's Request
See original GitHub issueI’m trying to implement facebook auth, based on passport.js
. The very first problem I’ve get with it was with request to GraphQL’s /me
after logging in (my access token wasn’t sent to GraphQL by default), but it was easy to do with credentials: 'same-origin'
in whatwg-fetch
. The issue is that the same doesn’t work from server side (node-fetch
doesn’t support using of XMLHttpRequest cookies).
Can you recommend any way to pass id_token
cookie through server-side app on backend request? Or, maybe they are some alternatives to fetch
or proposed access policy?
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Fetch API with Cookie - Stack Overflow
Then calling GET /api/users/ with credentials: 'include' and got 401 unauth, because of no cookies were sent with the request.
Read more >ID Token and Access Token: What Is the Difference? - Auth0
Learn what ID and access tokens are and how to correctly use them in the OpenID Connect and OAuth context.
Read more >Using the ID token - Amazon Cognito - AWS Documentation
The ID token is a JSON web token (JWT) that contains claims about the identity of the authenticated user, such as name ,...
Read more >Verify the Google ID token on your server side | Authentication
After Google returns an ID token, it's submitted by an HTTP POST method ... csrf_token_cookie = self.request.cookies.get('g_csrf_token')
Read more >Getting an ID Token - OAuth 2.0 Simplified
We build up a POST request to Google's token endpoint containing our app's client ID and secret, as well as the authorization code...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think that
core/fetch
HTTP client utility must be context-aware (regardless of what library you’re using -fetch
,superagent
,jQuery.ajax
), so instead of using a globalfetch
utility, you would rather need to either instantiate a new instance of it each time you need to render a React app (insrc/server.js/get('*', ...)
andsrc/client.js
), or you can pass context as an argument, so thatfetch('/api/data')
becomesfetch(context, '/api/data')
. This way you will be able to grab theid_token
from cookies during server-side rendering and pass it as part of a context that is passed to thefetch
utility. Thefetch
utility can then send thisid_token
via Authorize header for example. This same pattern might be used to passcache
object to the HTTP client utility, which would allow to avoid sending any Ajax request on the client during the initial rendering. What do you think?P.S.: A PR with this feature is more than welcome!
@mykhas thank you very much for crating this issue! Unfortunately, we have close it due to inactivity. Feel free to re-open it or join our Discord channel for discussion.
NOTE: The
main
branch has been updated with React Starter Kit v2, using JAM-style architecture.