Is storing an OAuth token in cookies bad practise?

前端 未结 3 1814
隐瞒了意图╮
隐瞒了意图╮ 2020-12-16 14:49

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

相关标签:
3条回答
  • 2020-12-16 15:20

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

    0 讨论(0)
  • 2020-12-16 15:38

    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.

    0 讨论(0)
  • 2020-12-16 15:43

    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.

    0 讨论(0)
提交回复
热议问题