I've spent a few days trying to figure out a secure authentication method for SPA/React (client-side).
Most of the tutorials I've read in the wild contradict each other.
One says have to store in Cookies another in Local Storage, one says don't need to use refresh token, one says have to use a refresh token.
I'm building a React SPA app for the frontend and Express for the API (backend). Both are stored in the same domain:
- React:
example.com
- Express:
api.example.com
orexample.com/api
Is it enough to secure my application by using Cookie (access token JWT):
- httpOnly:✅
- secure: ✅
- sameSite:
strict
- without refresh token
This matches the answer here: https://stackoverflow.com/a/57779076/11340631
The question is:
- Is this safe enough?
- How long does it take to set the expiration of the access token?
- Is this as per Oauth recommendation?: https://datatracker.ietf.org/doc/html/draft-ietf-oauth-browser-based-apps
- What if my access token is stolen? For example, my friend is using my PC and he stole my cookies and use it in his PC browser.
I really hope to get the answer here, any answer is appreciated.