Good idea to use REST token authentication for AJAX web apps?

筅森魡賤 提交于 2019-12-06 13:42:41

TokenAuthentication is mostly used with native clients connecting to server, things like iOS, Android or windows apps etc..

When dealing with ajax (using web app), you should use SessionAuthentication. This saves you from providing any additional data. The only requirement is for user to be logged in.

TokenAuthentication and SessionAuthentication behavior is similar when you look at the HTTP telegrams: both of them are sending in plain text the username and password during login and afterwards they mark their requests with a hash uniquely identifying them to the system (token uses the headers, sessions are persisted on server-side cookies).

One has to understand that session authentication keeps the sessions in the dB back-end, which do requires maintenance in a production system (who cleans up the expired sessions ?), or it may be a performance bottleneck, demanding cache-based solutions.

I would choose SessionAuthentication only if I would need to implement some kind of timeout mechanism, so that I would render sessions as expired after let's say 15 minutes of inactivity, or to inspect if an user has multiple logins (from several browsers which most likely resides in several machines).

Bottom line: you are perfectly fine with TokenAuthentication, if you go with SessionAuthentication care that it will truly serve your purpose, otherwise it brings some issues to deal with not so obvious.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!