Commit 6996df3504a840d90a90e8ca972ea81926dbced7

Authored by Victor Costa
1 parent 85741fbb

oauth_provider: consider the environment when search for users

plugins/oauth_provider/lib/oauth_provider_plugin.rb
... ... @@ -13,20 +13,17 @@ class OauthProviderPlugin < Noosfero::Plugin
13 13 # Currently supported options are :active_record, :mongoid2, :mongoid3, :mongo_mapper
14 14 orm :active_record
15 15  
  16 + domain = Domain.find_by_name(request.host)
  17 + environment = domain ? domain.environment : Environment.default
  18 +
16 19 # This block will be called to check whether the resource owner is authenticated or not.
17 20 resource_owner_authenticator do
18   - User.find_by_id(session[:user]) || redirect_to('/account/login')
19   - #fail "Please configure doorkeeper resource_owner_authenticator block located in #{__FILE__}"
20   - # Put your resource owner authentication logic here.
21   - # Example implementation:
22   - # User.find_by_id(session[:user_id]) || redirect_to(new_user_session_url)
  21 + environment.users.find_by_id(session[:user]) || redirect_to('/account/login')
23 22 end
24 23  
25 24 # If you want to restrict access to the web interface for adding oauth authorized applications, you need to declare the block below.
26 25 admin_authenticator do
27   - # Put your admin authentication logic here.
28   - # Example implementation:
29   - User.find_by_id(session[:user]) || redirect_to('/account/login')
  26 + environment.users.find_by_id(session[:user]) || redirect_to('/account/login')
30 27 end
31 28  
32 29 # Authorization Code expiration time (default 10 minutes).
... ...