授予访问端点的权限是一种好习惯吗?
例如
POST /permissions {method: "GET", resource: {href: "/users/*"}}
-> 201 {href: "/permissions/12345", id: 12345}
POST /roles/123/rolePermissions {permission: {id: 12345}}
然后检查具有给定模式的权限......
例如,如果我想允许朋友编辑我的某篇文章,我可以执行以下操作:
GET /users/13/userPermissions
-> 200 {items: [{id: 99, shares: [], permission: {id: 1234, method: "PUT", resource: {href: "/article/1"}}}, ...]}
客户端使用我的自定义权限打印一个花哨的表,现在我可以选择权限1234,并与我的朋友分享:
POST /userPermissions/99/shares {user: {id: 15}}
-> 201 {id: 111111}
-> new permission to "DELETE /userPermissions/99/shares/111111" is created and given to me (13)
-> permission to "PUT /article/1" given to my friend (15)
之后我也可以删除它
DELETE /userPermissions/99/shares/11111
-> permission to "PUT /article/1" revoked from my friend (15)
-> permission to "DELETE /userPermissions/99/shares/111111" revoked from me (13) and deleted
如果这种方法无法存储和检查权限,那么最佳做法是什么?
答案 0 :(得分:1)
不,不是。 REST只是一种交付方式。您可以进行其他交付,例如SOAP,纯HTML Web应用程序,flash,java等等......因此授权逻辑必须独立于它们,它应该是业务逻辑的一部分,或者它应该在业务逻辑和交付。