OAuth redirect lost sometimes due to session store race (#2514) #2515
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR solves the issue (described in greater detail in #2514) where Feathers OAuth does not always redirect to the path requested by the
redirect
query parameter and instead redirects to the root of the site specified byauthentication.oauth.redirect
. This happens only a small percentage of the time and only when using an external Express session store that is somewhat slow.The issue is due to a race condition where the Express session created during a request to
/oauth/:name
does not get saved before the browser makes a subsequent request in the OAuth flow (to/oauth/connect/:name
) and that causes Express to create a new session, effectively discarding the original session which contains theredirect
parameter.The fix is for Feathers to explicitly save the Express session in the
/oauth/:name
handler before responding with the redirect to/oauth/connect/:name
.This fix is consistent with guidance from Express session's docs (see bolded phrase):
Also see issues like https://github.com/expressjs/session/issues/660
Fixes: #2514
Other Information
Tests run
npm run test
Note on TypeScript version
The newer version of TypeScript that gets installed with a fresh clone of this repo does not compile successfully due to TS changing the default type of the error in catch blocks to
unknown
. So I ran my tests by pinning TypeScript to an older version.