lhc 12.0.3 → 12.1.0

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: ad768b826ac53e7175609b97943ffbb746f514c1f99bdfb7174d48307052df4c
4
- data.tar.gz: 7bcbcf0c7d08b7be73eb7ece1b688fb8be003d68d269b4ef70d5994fab9cc07a
3
+ metadata.gz: 20beb1550ea6286010ac46dd969bcdd8cdcc4dbb968d5ebbfdf3b591eb118fb1
4
+ data.tar.gz: c219d6d5bfb4b7a00e7c2d2273162d2cf3b1d106742dc803e9abfaa0987c0fae
5
5
  SHA512:
6
- metadata.gz: c181e5bc874086374c453e6056d31c948eaa2d4a869dfa002819e3236d486c6b98e7d3c058e5cca2dbc423d58a0777b3208471426dc8e47c085cc92cedef6afb
7
- data.tar.gz: 3203b6a2ae1c3180271b7d7f16b5dbf1b499cad6c623145139d74a5e65bd59d7376267702417e483f6c82b0942d89e72b0b24fe7e978b349de75a9a1cffd6e55
6
+ metadata.gz: 609167a963677ba5191a5579a43b9740c08b16be259041da52cb5459e5e5c0eb481361a4115323b6bfa1c444b068669760dc530a5cbaea35af747f63650cea62
7
+ data.tar.gz: 47e4cbc20c4ab60befb908c719b0c7625a982325b7b756c48ceedec11f649c082c0715a26b0e8f76ce6124b1ef5dd2b0df475e1c13cfef568147b989a317dbe7
data/README.md CHANGED
@@ -58,6 +58,7 @@ use it like:
58
58
  * [Authentication Interceptor](#authentication-interceptor)
59
59
  * [Bearer Authentication](#bearer-authentication)
60
60
  * [Basic Authentication](#basic-authentication)
61
+ * [Body Authentication](#body-authentication)
61
62
  * [Reauthenticate](#reauthenticate)
62
63
  * [Bearer Authentication with client access token](#bearer-authentication-with-client-access-token)
63
64
  * [Caching Interceptor](#caching-interceptor)
@@ -92,6 +93,7 @@ use it like:
92
93
 
93
94
 
94
95
 
96
+
95
97
  ## Basic methods
96
98
 
97
99
  Available are `get`, `post`, `put` & `delete`.
@@ -549,6 +551,20 @@ Adds the following header to the request:
549
551
 
550
552
  Which is the base64 encoded credentials "username:password".
551
553
 
554
+ ##### Body Authentication
555
+
556
+ ```ruby
557
+ LHC.post('http://local.ch', auth: { body: { userToken: 'dheur5hrk3' } })
558
+ ```
559
+
560
+ Adds the following to body of all requests:
561
+
562
+ ```
563
+ {
564
+ "userToken": "dheur5hrk3"
565
+ }
566
+ ```
567
+
552
568
  ##### Reauthenticate
553
569
 
554
570
  The current implementation can only offer reauthenticate for _client access tokens_. For this to work the following has to be given:
@@ -4,8 +4,13 @@ class LHC::Auth < LHC::Interceptor
4
4
  include ActiveSupport::Configurable
5
5
  config_accessor :refresh_client_token
6
6
 
7
+ def before_raw_request
8
+ body_authentication! if auth_options[:body]
9
+ end
10
+
7
11
  def before_request
8
- authenticate!
12
+ bearer_authentication! if auth_options[:bearer]
13
+ basic_authentication! if auth_options[:basic]
9
14
  end
10
15
 
11
16
  def after_response
@@ -16,12 +21,9 @@ class LHC::Auth < LHC::Interceptor
16
21
 
17
22
  private
18
23
 
19
- def authenticate!
20
- if auth_options[:bearer]
21
- bearer_authentication!
22
- elsif auth_options[:basic]
23
- basic_authentication!
24
- end
24
+ def body_authentication!
25
+ auth = auth_options[:body]
26
+ request.options[:body] = (request.options[:body] || {}).merge(auth)
25
27
  end
26
28
 
27
29
  def basic_authentication!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LHC
4
- VERSION ||= '12.0.3'
4
+ VERSION ||= '12.1.0'
5
5
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ describe LHC::Auth do
6
+ before(:each) do
7
+ LHC.config.interceptors = [LHC::Auth]
8
+ end
9
+
10
+ it 'adds body authentication to the existing request body' do
11
+ stub_request(:post, "http://local.ch/")
12
+ .with(body: {
13
+ message: 'body',
14
+ userToken: 'dheur5hrk3'
15
+ }.to_json)
16
+
17
+ LHC.post('http://local.ch', auth: { body: { userToken: 'dheur5hrk3' } }, body: {
18
+ message: 'body'
19
+ })
20
+ end
21
+
22
+ it 'adds body authentication to an empty request body' do
23
+ stub_request(:post, "http://local.ch/")
24
+ .with(body: {
25
+ userToken: 'dheur5hrk3'
26
+ }.to_json)
27
+
28
+ LHC.post('http://local.ch', auth: { body: { userToken: 'dheur5hrk3' } })
29
+ end
30
+
31
+ it 'adds nothing if request method is GET' do
32
+ stub_request(:get, "http://local.ch/")
33
+
34
+ LHC.get('http://local.ch', auth: { body: { userToken: 'dheur5hrk3' } })
35
+ end
36
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhc
3
3
  version: !ruby/object:Gem::Version
4
- version: 12.0.3
4
+ version: 12.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhc/contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-14 00:00:00.000000000 Z
11
+ date: 2020-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -325,6 +325,7 @@ files:
325
325
  - spec/interceptors/after_response_spec.rb
326
326
  - spec/interceptors/auth/basic_auth_spec.rb
327
327
  - spec/interceptors/auth/bearer_spec.rb
328
+ - spec/interceptors/auth/body_spec.rb
328
329
  - spec/interceptors/auth/long_basic_auth_credentials_spec.rb
329
330
  - spec/interceptors/auth/reauthentication_configuration_spec.rb
330
331
  - spec/interceptors/auth/reauthentication_spec.rb
@@ -476,6 +477,7 @@ test_files:
476
477
  - spec/interceptors/after_response_spec.rb
477
478
  - spec/interceptors/auth/basic_auth_spec.rb
478
479
  - spec/interceptors/auth/bearer_spec.rb
480
+ - spec/interceptors/auth/body_spec.rb
479
481
  - spec/interceptors/auth/long_basic_auth_credentials_spec.rb
480
482
  - spec/interceptors/auth/reauthentication_configuration_spec.rb
481
483
  - spec/interceptors/auth/reauthentication_spec.rb