Recently, my web app started throwing the following:
{error: "invalid_token", errorDescription: "`state` does not match."}
This error only occurs on the production site, wherein, a login form on https://codus.io
has a callback to https://app.codus.io
(in development, the origins are 0.0.0.0:5000
and 0.0.0.0:5001
).
I’m a little confused about the “state does not match” error, because according to Chrome’s developer tools, the request to /authenticate
made by auth0.js a request is made with state=wf3x7LxpvZhvP~u8Gk1scsYhp24wEva6
, and in the callback, the hash has the EXACT same state:
state=wf3x7LxpvZhvP~u8Gk1scsYhp24wEva6
I repeated this experiment a second time, and once again, the states were identical.
Following the advice of other similar topics, I checked that my parseHash
function is only running once; I added a console.log
before the only parseHash
in the entire codebase, and it only logs once. Relevant code from my site:
if (window.location.hash) {
await new Promise((resolve) => {
console.log('Calling parseHash');
webAuth.parseHash({ hash: window.location.hash }, (err, res) => {
console.log('parseHash completed with err:', err, 'res:', res);
resolve();
});
});
}
“calling parseHash” only appears once in the console, followed by
parseHash completed with err: {error: "invalid_token", errorDescription: "`state` does not match."} res: undefined
What could be causing this issue?