quiet-winter-64533
06/06/2023, 1:48 AMFrontendApi.getSession() fails I redirect to /ui/login?return_to=${window.location.href}. This allows me to dynamically redirect to the app that is running (to allow for pr builds), rather than adding the redirect to ory directly.
The above works fine and the user can login and a secure cookie is returned. I then add the cookie to the graphql request headers to pass it to my server. The server then needs to validate the cookie, and this is where I have run into an issue.
In the server I use FrontendApi.toSession({cookie}) to validate the received cookie, however this verification fails. I am assuming it is failing because the cookie has been set with sameSite=Strict and the server is running on api.heroku.com (even though we have a CNAME for incoming requests to api.example.com). So the cookie url and server url don't match.
Do you think this is the issue and if so, what is the best way to verify a secure cookie that is passed from a client to a server? Would modifying the headers in my toSession request fix the issue:
const modifiedOrigin = '<<https://api.example.com>>';
const toSessionRes = await ory.toSession(
{ cookie },
{
headers: {
Origin: modifiedOrigin,
Referer: modifiedOrigin,
},
},
);
Thanks in advance for any help!
P.S. This all works fine locally using the Ory tunnel.limited-photographer-61008
06/06/2023, 12:45 PMAccess-Control-Allow-Origin response header can’t be *.
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#requests_with_credentials
The sameSite=Strict shouldn’t matter as long as the domains are the same. You can easily check the network tab to see if the cookie is being sent in the request or not.
For the request sent by the server, it doesn’t actually matter which Ory domain you use. It doesn’t have the same limitations as the browser.quiet-winter-64533
06/07/2023, 12:52 AMhttps:// 😳
So that was the fix. No need to send any extra headers in the toSession request from the server.
Thanks again for the assist!