lhs 21.3.0 → 21.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cadb661567a1a911f12d612030d14ca963216bc6cca0874525b50ec9afe6d2c1
4
- data.tar.gz: f110c85be3c7ff12f00797f1268f14ba9376c235e1d8dbe9665fb51515f7c0b2
3
+ metadata.gz: c43753bff8b039bf6b5b2384333afcc1d09da6c61f1616b06751c7a023e0fbc0
4
+ data.tar.gz: ee5cd17ace1e7f82fc8a713dc493543e800658bd76909ddb026951d84f31c2df
5
5
  SHA512:
6
- metadata.gz: ed5dc79199bd8563b951f0131dbb4965e7133898f703104f054cbffe52953ed2c6d9526d046d2077d7b1420ba15e6a3c1ef6ac8168a8087c62d9cc50e227a8cc
7
- data.tar.gz: 2cf77b9a2955eac7cf408f3f35174863b6b773133149b77e0aea47a74808d5d43ab43d99e00cd7bdab4a1c41e8c59c831d31dfae64f8f5d3723f65102288aa06
6
+ metadata.gz: 14d9ddf1745b15e1c635060eec564a3e578f31829e24dede722ca5509a1dffeefec3fb0daaeb27c94f3c9854314d41fe9042cccfbd04ca3fdc2bab3a32bb9120
7
+ data.tar.gz: ac97fc333b97f8492bc519b401b68377af441e398486ceaea183d8b006015b691d1aad9a0f518ebf5367cf4427098d767e96354813da94807021195a38f3e997
data/README.md CHANGED
@@ -136,6 +136,7 @@ record.review # "Lunch was great
136
136
  * [Disable request cycle cache](#disable-request-cycle-cache)
137
137
  * [Automatic Authentication (OAuth)](#automatic-authentication-oauth)
138
138
  * [Configure multiple auth providers (even per endpoint)](#configure-multiple-auth-providers-even-per-endpoint)
139
+ * [Configure providers](#configure-providers)
139
140
  * [Option Blocks](#option-blocks)
140
141
  * [Request tracing](#request-tracing)
141
142
  * [Extended Rollbar Logging](#extended-rollbar-logging)
@@ -150,6 +151,7 @@ record.review # "Lunch was great
150
151
 
151
152
 
152
153
 
154
+
153
155
  ## Installation/Startup checklist
154
156
 
155
157
  - [ ] Install LHS gem, preferably via `Gemfile`
@@ -2545,6 +2547,36 @@ class Record < LHS::Record
2545
2547
  end
2546
2548
  ```
2547
2549
 
2550
+ ### Configure providers
2551
+
2552
+ If you're using LHS service providers, you can also configure auto auth on a provider level:
2553
+
2554
+ ```ruby
2555
+ # app/models/providers/localsearch.rb
2556
+ module Providers
2557
+ class Localsearch < LHS::Record
2558
+
2559
+ provider(
2560
+ oauth: true
2561
+ )
2562
+ end
2563
+ end
2564
+ ```
2565
+
2566
+ or with multiple auth providers:
2567
+
2568
+ ```ruby
2569
+ # app/models/providers/localsearch.rb
2570
+ module Providers
2571
+ class Localsearch < LHS::Record
2572
+
2573
+ provider(
2574
+ oauth: :provider_1
2575
+ )
2576
+ end
2577
+ end
2578
+ ```
2579
+
2548
2580
  ## Option Blocks
2549
2581
 
2550
2582
  In order to apply options to all requests performed in a give block, LHS provides option blocks.
@@ -532,7 +532,7 @@ class LHS::Record
532
532
  end
533
533
 
534
534
  endpoint = find_endpoint(options[:params], options.fetch(:url, nil))
535
- if auto_oauth? || (endpoint.options&.dig(:oauth) && LHS.config.auto_oauth)
535
+ if auto_oauth? || (endpoint.options&.dig(:oauth) && LHS.config.auto_oauth) || options[:oauth]
536
536
  inject_interceptor!(
537
537
  options.merge!(record: self),
538
538
  LHS::Interceptors::AutoOauth::Interceptor,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LHS
4
- VERSION = '21.3.0'
4
+ VERSION = '21.3.1'
5
5
  end
@@ -125,5 +125,45 @@ describe 'Auto OAuth Authentication', type: :request, dummy_models: true do
125
125
  expect(record_request_per_endpoint_provider_2).to have_been_requested
126
126
  end
127
127
  end
128
+
129
+ context 'with provider enabled for auto oauth' do
130
+
131
+ let(:token) { ApplicationController::ACCESS_TOKEN }
132
+
133
+ let(:record_request) do
134
+ stub_request(:get, "http://internalservice/v2/records/1")
135
+ .with(
136
+ headers: { 'Authorization' => "Bearer #{token}" }
137
+ ).to_return(status: 200, body: { name: 'Record' }.to_json)
138
+ end
139
+
140
+ let(:records_request) do
141
+ stub_request(:get, "http://internalservice/v2/records?color=blue")
142
+ .with(
143
+ headers: { 'Authorization' => "Bearer #{token}" }
144
+ ).to_return(status: 200, body: { items: [{ name: 'Record' }] }.to_json)
145
+ end
146
+
147
+ before do
148
+ LHS.configure do |config|
149
+ config.auto_oauth = -> { access_token }
150
+ end
151
+ LHC.configure do |config|
152
+ config.interceptors = [LHC::Auth]
153
+ end
154
+ record_request
155
+ records_request
156
+ end
157
+
158
+ after do
159
+ LHC.config.reset
160
+ end
161
+
162
+ it 'applies OAuth credentials for the individual request automatically' do
163
+ get '/automatic_authentication/oauth_with_provider'
164
+ expect(record_request).to have_been_requested
165
+ expect(records_request).to have_been_requested
166
+ end
167
+ end
128
168
  end
129
169
  end
@@ -19,4 +19,11 @@ class AutomaticAuthenticationController < ApplicationController
19
19
  }
20
20
  }
21
21
  end
22
+
23
+ def o_auth_with_provider
24
+ render json: {
25
+ record: DummyRecordWithAutoOauthProvider.find(1).as_json,
26
+ records: DummyRecordWithAutoOauthProvider.where(color: 'blue').as_json
27
+ }
28
+ end
22
29
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DummyRecordWithAutoOauthProvider < Providers::InternalServices
4
+ endpoint 'http://internalservice/v2/records'
5
+ endpoint 'http://internalservice/v2/records/{id}'
6
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Providers
4
+ class InternalServices < LHS::Record
5
+ provider(oauth: true)
6
+ end
7
+ end
@@ -6,6 +6,7 @@ Rails.application.routes.draw do
6
6
  # Automatic Authentication
7
7
  get 'automatic_authentication/oauth' => 'automatic_authentication#o_auth'
8
8
  get 'automatic_authentication/oauth_with_multiple_providers' => 'automatic_authentication#o_auth_with_multiple_providers'
9
+ get 'automatic_authentication/oauth_with_provider' => 'automatic_authentication#o_auth_with_provider'
9
10
 
10
11
  # Request Cycle Cache
11
12
  get 'request_cycle_cache/simple' => 'request_cycle_cache#simple'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhs
3
3
  version: !ruby/object:Gem::Version
4
- version: 21.3.0
4
+ version: 21.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhs/graphs/contributors
@@ -388,12 +388,14 @@ files:
388
388
  - spec/dummy/app/models/concerns/.keep
389
389
  - spec/dummy/app/models/dummy_customer.rb
390
390
  - spec/dummy/app/models/dummy_record.rb
391
+ - spec/dummy/app/models/dummy_record_with_auto_oauth_provider.rb
391
392
  - spec/dummy/app/models/dummy_record_with_multiple_oauth_providers1.rb
392
393
  - spec/dummy/app/models/dummy_record_with_multiple_oauth_providers2.rb
393
394
  - spec/dummy/app/models/dummy_record_with_multiple_providers_per_endpoint.rb
394
395
  - spec/dummy/app/models/dummy_record_with_oauth.rb
395
396
  - spec/dummy/app/models/dummy_user.rb
396
397
  - spec/dummy/app/models/providers/customer_system.rb
398
+ - spec/dummy/app/models/providers/internal_services.rb
397
399
  - spec/dummy/app/views/error_handling_with_chains/error.html.erb
398
400
  - spec/dummy/app/views/error_handling_with_chains/show.html.erb
399
401
  - spec/dummy/app/views/form_for.html.erb
@@ -613,12 +615,14 @@ test_files:
613
615
  - spec/dummy/app/models/concerns/.keep
614
616
  - spec/dummy/app/models/dummy_customer.rb
615
617
  - spec/dummy/app/models/dummy_record.rb
618
+ - spec/dummy/app/models/dummy_record_with_auto_oauth_provider.rb
616
619
  - spec/dummy/app/models/dummy_record_with_multiple_oauth_providers1.rb
617
620
  - spec/dummy/app/models/dummy_record_with_multiple_oauth_providers2.rb
618
621
  - spec/dummy/app/models/dummy_record_with_multiple_providers_per_endpoint.rb
619
622
  - spec/dummy/app/models/dummy_record_with_oauth.rb
620
623
  - spec/dummy/app/models/dummy_user.rb
621
624
  - spec/dummy/app/models/providers/customer_system.rb
625
+ - spec/dummy/app/models/providers/internal_services.rb
622
626
  - spec/dummy/app/views/error_handling_with_chains/error.html.erb
623
627
  - spec/dummy/app/views/error_handling_with_chains/show.html.erb
624
628
  - spec/dummy/app/views/form_for.html.erb