-
There are two ways to handle these in web applications.
-
Using
sessionsmethod orjwttokenized way to handle the auth and auth.
-
express-sessionexpress module with built in cookies based session management system and also integrate with stores to save the sessions. -
jsonwebtokenfor managing the authentication and session management, it is stateless. -
passportjsfor managing the session with local strategy and asessionslso OAuth
-
Consist of three parts
- Header(Algorithm & token type)
- Payload(data)
- Signature(Verification Sign)
- Cookies are set in the server on the login request and sent to the client using the
Set-Cookieheader in the response and there after sent from the client for all the requests to identify the user.
Secure=> Used to tell the browser to send cookies over https only.HttpOnly=> Makes the cookies accesible only in the server, client side js cannot access it using document.cookie.SameSite=> Blocks cross origin requestDomain and Path=> These can be changes accordingly for securityExpires or Max-Age=> This is used to persist the cookie for the specified time