I'm learning about authentication in Java and Spring and about difference between session and token based authentication.
I know that in session based authentication the user sends the username/password to server. It could send the credentials using a html form or basic authentication. After that the server create a session and send the session id in a cookie header like this set-cookie: sessionid
, and when the user make another request it will use the session id in a cookie header like this cookie: sessionid
. And the server compare the session id stored on the cookie against the session information stored in the memory to verify user’s identity and sends response with the corresponding state.
I'm not sure what's happen in the token based authentication. The user will send the username/password to server in the same way like in the first case: html form, basic authentication, etc. The server creates JWT and send the JWT to the user browser usually in the localstorage. But what I don't understand is how the server sends the JWT to client? Does it send the JWT in a Header like this set-authorization: jwt
? What is the name of the header where the jwt is put? And after that when the client does a new request the JWT will be in an authorization header like this Authorization: Bearer jwt
. So I don't understand how the JWT is sent from the server to the browser. Any feedback will be apreciated! Thank you!