I've been wracking my brain and googling away for ages without coming up with a satisfactory way of handling this. I want to write a nice fully RESTful service to return resources, but the data you have permission to read (or write) variest per-resource depending on your role. So, for example, a user may be able to see their private phone number on their profile, and so may a site administrator, but another user wouldn't. An anonymous visitor might not be able to see another user's real name, but other users (and the site admin) could do. There are around 4 or 5 access levels and rules about which attributes can be read or written. The writing I'm happy with as the client can PUT changes and the server is not bound to accept them all (or at all), but the reading is my problem.
<user>
<id>jimbob</id>
<real-name>Jim Roberts</real-name> <!-- only logged-in users should see this -->
<phone-number>+1 42424151</phone-number> <!-- only the user and admin users should see this -->
</user>
I want to have a properly cacheable user-profile resource which contains all the public data, but how do I model all the stuff that only certain users can see? I could up to 4 links to extra information, most of which would return Unauthorized errors for most users, with each link holding the extra information related to a role. But that seems very inefficient and also ties the clients into the role concept, when previously all they needed to know about was users. Are there any better ideas?
<user>
<id>...</id>
<link rel="more" href="extra-user-profile-data-for-logged-in-users"/>
<link rel="more" href="extra-user-profile-data-for-senior-users"/>
<link rel="more" href="extra-user-profile-data-for-admin-users"/>
<link rel="more" href="extra-user-profile-data-for-superadmin-users"/>
</user>
Please note - I am not struggling with any of
- Authentication
- Resource-level access control
- Implementing access control or authorisation on the server side
I am struggling with
- How to represent resources which in a 'normal' HTML website would appear different to different people, in a truly RESTful way.
This seems like a really common problem that everyone should be having, but I can't find anything on it! Please help!