Token Based Auth System [state-less]
![Token Based Auth System [state-less]](/_next/image?url=https%3A%2F%2Fcloudmate-test.s3.us-east-1.amazonaws.com%2Fuploads%2Fcovers%2F662e9149ea7b8adaf16495b0%2Ff4e28b41-8d8d-42bd-8b0c-e3b86fbebda5.png&w=3840&q=75)
In a token-based system, HS256 and RS256 are the two most common algorithms used to sign the token.
1. HS256
This method is mostly used in
monolithapplication, where it only requires single key.Token Based auth is state-less it means not need to store user
sessions, Instead server provides aSigned_Token(digital pass) to user.For every sub-sequent query u must have to provide that
Signed_Tokento verification.
How it’s work?
Login - user submit their credential to server.
Verification and creation - if credential is correct against DB, it creates
Signed_Token(JWT) usingsecret_keysend back to client.Cookie - Server send back response with header of
set_cookieincludesSigned_Tokenwith flagshttponlysecure.Browser - it automatically store the
Signed_Token.Subsequent request - in every future server request, browser attach cookie of
Signed_Tokenheader requests.Server validation - it pull the
Signed_Tokenfrom header cookie and verify it’sdigital signatureandexpiry_dateusingsecret_key, and process the request.
2. RS256
This method is best for micro_service distributed_systems application.
How it’s work?
- The process is same as HS256 but
Auth_serverkeepsprivate_keyto sign in thetokenand givespublic_keyto other services to verify thetoken



![Session Based Auth System [state-full]](/_next/image?url=https%3A%2F%2Fcloudmate-test.s3.us-east-1.amazonaws.com%2Fuploads%2Fcovers%2F662e9149ea7b8adaf16495b0%2Fe59a4233-21ac-418e-8af0-9057d2e04cdf.png&w=3840&q=75)