Do sessions really violate RESTfulness?

前端 未结 7 1195
小蘑菇
小蘑菇 2020-11-22 08:35

Is using sessions in a RESTful API really violating RESTfulness? I have seen many opinions going either direction, but I\'m not convinced that sessions are RESTless

相关标签:
7条回答
  • 2020-11-22 09:06

    HTTP transaction, basic access authentication, is not suitable for RBAC, because basic access authentication uses the encrypted username:password every time to identify, while what is needed in RBAC is the Role the user wants to use for a specific call. RBAC does not validate permissions on username, but on roles.

    You could tric around to concatenate like this: usernameRole:password, but this is bad practice, and it is also inefficient because when a user has more roles, the authentication engine would need to test all roles in concatenation, and that every call again. This would destroy one of the biggest technical advantages of RBAC, namely a very quick authorization-test.

    So that problem cannot be solved using basic access authentication.

    To solve this problem, session-maintaining is necessary, and that seems, according to some answers, in contradiction with REST.

    That is what I like about the answer that REST should not be treated as a religion. In complex business cases, in healthcare, for example, RBAC is absolutely common and necessary. And it would be a pity if they would not be allowed to use REST because all REST-tools designers would treat REST as a religion.

    For me there are not many ways to maintain a session over HTTP. One can use cookies, with a sessionId, or a header with a sessionId.

    If someone has another idea I will be glad to hear it.

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