现在我的问题是,如果服务器没有保存任何关于会话 id 的信息,它如何验证来自客户端的会话?
play 的作用是通过一个密钥对您的会话数据进行签名,例如 KEY(它是您在 application.conf 中设置的 application.secret)并生成一个字母数字数据。然后它将数据和加密数据附加到 cookie 并将其发送回
加密数据= 5d9857e8a41f94ecb2e4e957cd3ab4f263cfbdea
数据 = userEmail=sil@st.com&userName=silentprogrammer
如果您在正在运行的应用程序的浏览器中检查 cookie(右键单击浏览器->检查元素->应用程序->Cookie->您的 url),您可以看到类似
"5d9857e8a41f94ecb2e4e957cd3ab4f263cfbdea-userEmail=sil@st.com&userName=silentprogrammer"
For each request it gets the data part(userEmail=sil@st.com&userName=silentprogrammer
) signs the data again from the KEY and checks it to the alphanumeric data coming from request i.e. 5d9857e8a41f94ecb2e4e957cd3ab4f263cfbdea
if the both are equal(if data and encryption key is same) the session is confirmed otherwise session expire. You can confirm this by changing the data part from cookie in browser and sending the request again the session will not exist.
This is what I have observed