Is storing an OAuth token in cookies bad practise?

折月煮酒 提交于 2019-12-19 05:46:11

问题


Is storing an OAuth 2 token in cookies bad practise? If so, what are alternatives for a web app?


回答1:


I definitely wouldn't do it. When security is involved you should not store stuff, in places where others can access it. So don't store it anywhere, especially client-side.

That being said, it's not bad practice, per se if handled properly. See this comprehensive article about it.




回答2:


Whether you can store the access_token in cookies depends on following things:

  1. Is the access_token stored in cookie encrypted or not (it definitely should be)
  2. Access_token is a bearer token so it is not tied to browser flows. Cookies in general are meant for maintaining state in browsers. So if lifecycle of token is same as cookie, go ahead otherwise not. When I say lifecycle, I mean lifespan, etc.
  3. Also, please consider this fact too that access token is not identity token
  4. Access tokens are completely client side, and servers that generally use cookies to maintain sessions, mostly maintain matching server side session as well.

I hope this helps.




回答3:


Cookies have maxSize of 4kb. So if you are saving a lot of info in the token - you will get an error.



来源:https://stackoverflow.com/questions/41076736/is-storing-an-oauth-token-in-cookies-bad-practise

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