lhs 21.3.0 → 21.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +32 -0
- data/lib/lhs/concerns/record/request.rb +1 -1
- data/lib/lhs/version.rb +1 -1
- data/spec/auto_oauth_spec.rb +40 -0
- data/spec/dummy/app/controllers/automatic_authentication_controller.rb +7 -0
- data/spec/dummy/app/models/dummy_record_with_auto_oauth_provider.rb +6 -0
- data/spec/dummy/app/models/providers/internal_services.rb +7 -0
- data/spec/dummy/config/routes.rb +1 -0
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c43753bff8b039bf6b5b2384333afcc1d09da6c61f1616b06751c7a023e0fbc0
|
4
|
+
data.tar.gz: ee5cd17ace1e7f82fc8a713dc493543e800658bd76909ddb026951d84f31c2df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,
|
data/lib/lhs/version.rb
CHANGED
data/spec/auto_oauth_spec.rb
CHANGED
@@ -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
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -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.
|
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
|