I'm interested in how to implement OAuth in React using popup (window.open
).
For example I have:
mysite.com
— this is where I open the popup.passport.mysite.com/oauth/authorize
— popup.
The main question is how to create connection between window.open
(popup) and window.opener
(as it's known the window.opener is null due to cross-domain security therefore we can't use it anymore).
⇑
window.opener
is removed whenever you navigate to a different host (for security reasons), there is no way around it. The only option should be doing the payment in a frame if it is possible. The top document needs to stay on the same host.
Scheme:
Possible solutions:
- Check an opened window using
setInterval
described here. Using cross-storage (not worth it imho ).
So what's the best recommended approach in 2019?
Wrapper for React - https://github.com/Ramshackle-Jamathon/react-oauth-popup
I once encounter an issue on my oauth login flow with window.open/window.opener bug on ms-edge
My flow before this issue was
My flow after this issue was
Suggested by Khanh TO. OAuth popup with localStorage. Based on react-oauth-popup.
Scheme:
Code:
oauth-popup.tsx:
app.tsx