diff --git a/.ruby-version b/.ruby-version index 7ec1d6d..cd57a8b 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.1.0 +2.1.5 diff --git a/Gemfile.lock b/Gemfile.lock index ffb7659..ccdc06b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -50,11 +50,11 @@ GEM kramdown railties rspec_api_documentation - arel (6.0.0) + arel (6.0.3) builder (3.2.2) diff-lcs (1.2.5) erubis (2.7.0) - globalid (0.3.5) + globalid (0.3.6) activesupport (>= 4.1.0) i18n (0.7.0) json (1.8.3) @@ -65,7 +65,7 @@ GEM mime-types (>= 1.16, < 3) mime-types (2.6.1) mini_portile (0.6.2) - minitest (5.7.0) + minitest (5.8.0) mustache (0.99.8) nokogiri (1.6.6.2) mini_portile (~> 0.6.0) @@ -102,15 +102,15 @@ GEM rspec-core (~> 3.3.0) rspec-expectations (~> 3.3.0) rspec-mocks (~> 3.3.0) - rspec-core (3.3.1) + rspec-core (3.3.2) rspec-support (~> 3.3.0) - rspec-expectations (3.3.0) + rspec-expectations (3.3.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.3.0) - rspec-mocks (3.3.1) + rspec-mocks (3.3.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.3.0) - rspec-rails (3.3.2) + rspec-rails (3.3.3) actionpack (>= 3.0, < 4.3) activesupport (>= 3.0, < 4.3) railties (>= 3.0, < 4.3) @@ -124,7 +124,7 @@ GEM json (~> 1.4, >= 1.4.6) mustache (~> 0.99, >= 0.99.4) rspec (>= 3.0.0) - sprockets (3.2.0) + sprockets (3.3.0) rack (~> 1.0) sprockets-rails (2.3.2) actionpack (>= 3.0) @@ -141,3 +141,6 @@ PLATFORMS DEPENDENCIES rake stitches! + +BUNDLED WITH + 1.10.6 diff --git a/lib/stitches/api_key.rb b/lib/stitches/api_key.rb index 976d715..2ff1f4c 100644 --- a/lib/stitches/api_key.rb +++ b/lib/stitches/api_key.rb @@ -35,6 +35,7 @@ def do_call(env) client = ::ApiClient.where(key: key).first if client.present? env[@configuration.env_var_to_hold_api_client_primary_key] = client.id + env[@configuration.env_var_to_hold_api_client] = client @app.call(env) else UnauthorizedResponse.new("key invalid",@realm,@configuration.custom_http_auth_scheme) @@ -56,4 +57,4 @@ def initialize(reason,realm,custom_http_auth_scheme) end end -end \ No newline at end of file +end diff --git a/lib/stitches/configuration.rb b/lib/stitches/configuration.rb index 4de5c81..b68d9c7 100644 --- a/lib/stitches/configuration.rb +++ b/lib/stitches/configuration.rb @@ -12,6 +12,7 @@ def reset_to_defaults! @whitelist_regexp = nil @custom_http_auth_scheme = UnsetString.new("custom_http_auth_scheme") @env_var_to_hold_api_client_primary_key = NonNullString.new("env_var_to_hold_api_client_primary_key","STITCHES_API_CLIENT_ID") + @env_var_to_hold_api_client= NonNullString.new("env_var_to_hold_api_client","STITCHES_API_CLIENT") end # A RegExp that whitelists URLS around the mime type and api key requirements. @@ -45,6 +46,14 @@ def env_var_to_hold_api_client_primary_key=(new_env_var_to_hold_api_client_prima @env_var_to_hold_api_client_primary_key = NonNullString.new("env_var_to_hold_api_client_primary_key",new_env_var_to_hold_api_client_primary_key) end + def env_var_to_hold_api_client + @env_var_to_hold_api_client.to_s + end + + def env_var_to_hold_api_client=(new_env_var_to_hold_api_client) + @env_var_to_hold_api_client= NonNullString.new("env_var_to_hold_api_client",new_env_var_to_hold_api_client) + end + private class NonNullString diff --git a/lib/stitches/generator_files/app/controllers/api/api_controller.rb b/lib/stitches/generator_files/app/controllers/api/api_controller.rb index 0e0976e..32856cf 100644 --- a/lib/stitches/generator_files/app/controllers/api/api_controller.rb +++ b/lib/stitches/generator_files/app/controllers/api/api_controller.rb @@ -13,7 +13,9 @@ def current_user protected def api_client - @api_client ||= ::ApiClient.find(request.env[Stitches.configuration.env_var_to_hold_api_client_primary_key]) + @api_client ||= request.env[Stitches.configuration.env_var_to_hold_api_client] + # Use this if you want to look up the ApiClient instead of using the one placed into the env + # @api_client ||= ApiClient.find(request.env[Stitches.configuration.env_var_to_hold_api_client_primary_key]) end end diff --git a/lib/stitches/spec/test_headers.rb b/lib/stitches/spec/test_headers.rb index 2ddfb4d..74dbbfe 100644 --- a/lib/stitches/spec/test_headers.rb +++ b/lib/stitches/spec/test_headers.rb @@ -43,7 +43,7 @@ def set_authorization_header(headers,options) if api_client_key.kind_of?(Array) headers["Authorization"] = api_client_key.join(" ") else - headers["Authorization"] = "CustomKeyAuth key=#{api_client_key}" + headers["Authorization"] = "#{Stitches.configuration.custom_http_auth_scheme} key=#{api_client_key}" end end end diff --git a/spec/api_key_spec.rb b/spec/api_key_spec.rb index 68a49a8..e5d23f2 100644 --- a/spec/api_key_spec.rb +++ b/spec/api_key_spec.rb @@ -154,6 +154,10 @@ class ApiClient it "sets the api_client's ID in the environment" do expect(env[Stitches.configuration.env_var_to_hold_api_client_primary_key]).to eq(api_clients.first.id) end + + it "sets the api_client itself in the environment" do + expect(env[Stitches.configuration.env_var_to_hold_api_client]).to eq(api_clients.first) + end end context "unauthorized responses" do