doorkeeper-gem/doorkeeper — pull request #462 by JanStevens (2014-08-12 09:03:14+00:00)
Title: User Allowed for Application

hello,

This is still a work in process and I need a bit of guidance/advice where to place the code (so we dont drift away from the oauth spec).

The idea is to evaluate a block to see if the `current_resource_owner` is allowed to acquire access to the `application`. This can be handy for many reasons, like an admin app only accessible if the user is admin, creating users and then assign the applications they can access and so on.

Right now I have altered `authorizations_controller#new` and added my check `resource_owner_allowed_for?` this works and when the block returns false, I cannot continue and get access to the application.

```
resource_owner_allowed_for do |app_id, current_resource_owner|
false
end
```
What I would like to add/change:
- Correct place to place the check if the `current_resource_owner` is allowed the requested `application`
- Better error handling, right now I get "An error has occurred translation missing: en.doorkeeper.errors.messages"
- Specs to test the implementation

I made a small error in starting this branch meaning my commits from previous PR are also included, relevant changes are in the commits after Aug 11.