I have a Rails 4 application. I use devise for authentication and opro for providing oauth2 with my API. All requests are authorized with pundit policies and until now, this setup was totally fine.
Currently, my authorization is always done on a per-user basis. This makes sense, as usually every request is done on behalf of a particular user who is either authenticated in a session or by providing the oauth-token.
The new challenge is: I have certain API-consumers (let me call them devices from now on), whose requests cannot be seen as requests from a particular user. One is an Asterisk Server that can exchange information with the API, another is a GPS Tracking Box that continuously pushes trackpoints to the API.
Thus, I need to authorize certain API-operations on a per-device basis, meaning there is not necessarily a current_user
available. Having no current_user
however screws up my authorization concept.
I have already considered several approaches to the problem:
- creating dedicated users for each device and authorizing them to do the specific action
- pro: does not screw up my authorization scheme
- contra: would mean to rethink the
User
-Model, as currently I only have "natural users" that require name, birthday, email, etc
- creating dedicated controllers with adapted authorization scheme
- pro: high flexibility
- contra:
- authentication for devices required
- extra API endpoints required, does not feel very DRY
I am searching for a best-practice approach for such a situation. I believe this is not an extra-ordinary problem and there must be good solutions for this out there.