shopify-api-js
shopify-api-js copied to clipboard
Allows setting a domain-wide cookie in the oauth flow
WHY are these changes introduced?
Some OAuth flows require a domain-wide cookie instead of the usual behavior that only works within the starting domain. For example, if you start the OAuth flow in api.example.com
and then redirect the user to app.example.com
to finish it, you'll get a CookieNotFound error (check out issue #686).
WHAT is this pull request doing?
Allows to set an optional cookieDomain
param when calling shopifyApi
.
Type of change
- [X] Patch: Bug (non-breaking change which fixes an issue)
Checklist
- [X] I have used
yarn changeset
to create a draft changelog entry (do NOT update theCHANGELOG.md
file manually) - [X] I have added/updated tests for this change
- [X] I have documented new APIs/updated the documentation for modified APIs (for public APIs)
Forgot to add that this PR also changes the default path when setting the auth cookie.
Currently the auth cookie is valid only on exactly the same domain and the same path that started the OAuth flow, which works great when creating an app using Shopify's CLI but fails on other cases.
An example where the current config fails:
- OAuth flow starts in
https://api.example.com/auth/start
. The SDK sets the cookie on theapi.example.com
domain and/auth/start
path. - OAuth flow ends in
https://dashboard.example.com/login/oauth
with an error (CookieNotFound) because it won't be able to find the auth cookie since the domain and path doesn't match.
The PR changes the default behavior by making the auth cookie available on the root path but at the same time it allows setting a specific domain where to make the cookie readable, but if not domain is set then the current behavior of using the initial domain is kept.
Nice work!
Awesome work. I hope an admin merges this soon.
Yes please let's merge it 🙇🏽♂️
What will it take to get this merged?
Thanks very much the PR @cmelendez ! Really appreciate you taking the time to open this.
I'm going to get this reviewed by app sec and back to you.