diff options
| author | Xinhui | 2017-08-22 12:48:54 +0200 | 
|---|---|---|
| committer | Xinhui | 2017-08-22 14:52:49 +0200 | 
| commit | 49eeb2919090f26f5d16d446df6f5890fc71625a (patch) | |
| tree | a2d25a9a625ea836b0958041303d09b65ea92972 | |
| parent | 857ff70a1fead6e29fb372f830710655d44cb3cc (diff) | |
| download | chouette-core-49eeb2919090f26f5d16d446df6f5890fc71625a.tar.bz2 | |
API - Iboo controller for basic auth end points
| -rw-r--r-- | app/controllers/api/v1/iboo_controller.rb | 24 | ||||
| -rw-r--r-- | spec/controllers/api/v1/iboo_controller_spec.rb | 5 | 
2 files changed, 29 insertions, 0 deletions
| diff --git a/app/controllers/api/v1/iboo_controller.rb b/app/controllers/api/v1/iboo_controller.rb new file mode 100644 index 000000000..d1633560f --- /dev/null +++ b/app/controllers/api/v1/iboo_controller.rb @@ -0,0 +1,24 @@ +class Api::V1::IbooController < Api::V1::ChouetteController +  protected +  def begin_of_association_chain +    @current_organisation +  end + +  private +  def authenticate +    authenticate_with_http_basic do |login, token| +      api_key = Api::V1::ApiKey.find_by(token: token) +      user = User.find_by(username: login) + +      return unless api_key && user +      if api_key.organisation == user.organisation +        @current_user = user +        @current_organisation = user.organisation +      end +    end + +    unless @current_user && @current_organisation +      request_http_basic_authentication +    end +  end +end diff --git a/spec/controllers/api/v1/iboo_controller_spec.rb b/spec/controllers/api/v1/iboo_controller_spec.rb new file mode 100644 index 000000000..92b70711e --- /dev/null +++ b/spec/controllers/api/v1/iboo_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Api::V1::IbooController, type: :controller do + +end | 
