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,20 +13,17 @@ class OauthProviderPlugin < Noosfero::Plugin
13 # Currently supported options are :active_record, :mongoid2, :mongoid3, :mongo_mapper 13 # Currently supported options are :active_record, :mongoid2, :mongoid3, :mongo_mapper
14 orm :active_record 14 orm :active_record
15 15
  16 + domain = Domain.find_by_name(request.host)
  17 + environment = domain ? domain.environment : Environment.default
  18 +
16 # This block will be called to check whether the resource owner is authenticated or not. 19 # This block will be called to check whether the resource owner is authenticated or not.
17 resource_owner_authenticator do 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 end 22 end
24 23
25 # If you want to restrict access to the web interface for adding oauth authorized applications, you need to declare the block below. 24 # If you want to restrict access to the web interface for adding oauth authorized applications, you need to declare the block below.
26 admin_authenticator do 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 end 27 end
31 28
32 # Authorization Code expiration time (default 10 minutes). 29 # Authorization Code expiration time (default 10 minutes).