diff options
| -rw-r--r-- | app/controllers/api/v1/iboo_controller.rb | 14 | ||||
| -rw-r--r-- | spec/support/shared_context.rb | 3 |
2 files changed, 8 insertions, 9 deletions
diff --git a/app/controllers/api/v1/iboo_controller.rb b/app/controllers/api/v1/iboo_controller.rb index d1633560f..7ea4cc22e 100644 --- a/app/controllers/api/v1/iboo_controller.rb +++ b/app/controllers/api/v1/iboo_controller.rb @@ -6,18 +6,18 @@ class Api::V1::IbooController < Api::V1::ChouetteController private def authenticate - authenticate_with_http_basic do |login, token| + authenticate_with_http_basic do |code, token| api_key = Api::V1::ApiKey.find_by(token: token) - user = User.find_by(username: login) + organisation = Organisation.find_by(code: code) - return unless api_key && user - if api_key.organisation == user.organisation - @current_user = user - @current_organisation = user.organisation + return unless api_key && organisation + + if api_key.organisation == organisation + @current_organisation = organisation end end - unless @current_user && @current_organisation + unless @current_organisation request_http_basic_authentication end end diff --git a/spec/support/shared_context.rb b/spec/support/shared_context.rb index c08ee6163..1282518c1 100644 --- a/spec/support/shared_context.rb +++ b/spec/support/shared_context.rb @@ -1,8 +1,7 @@ shared_context 'iboo authenticated api user' do let(:api_key) { create(:api_key) } - let(:user) { create(:user, organisation: api_key.organisation ) } before do - request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(user.username, api_key.token) + request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(api_key.organisation.code, api_key.token) end end |
