faraday 1.7.2 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/faraday/request/authorization.rb +14 -7
- data/lib/faraday/version.rb +1 -1
- data/spec/faraday/request/authorization_spec.rb +8 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6441da03048f7371bd0cb898dd3e27c7be6382c67fc4901883e9dbe9841b56f
|
4
|
+
data.tar.gz: 0beb3f2da75282655fc46cd5540de96d5fef259dd35193ec9eb0d3163cc959d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ab1aa0e0c68c9348d9e180a903f01f2517bd38672fe1bdf056ceab4729e841944173e47dc26aa1b4fe16b2779f1a8102914ed594ea92d08feff6dc944412f0b
|
7
|
+
data.tar.gz: bc43fbac427062861e79d5328b60886a5b9c8783f707faa1fcfad064b9c6945f6a4e2a97dbad9ecadc1c1620b5327d651a764962764b7fc86e6d2fbd84ad0b4b
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'base64'
|
4
|
+
|
3
5
|
module Faraday
|
4
6
|
class Request
|
5
7
|
# Request middleware for the Authorization HTTP header
|
@@ -13,7 +15,8 @@ module Faraday
|
|
13
15
|
# @return [String] a header value
|
14
16
|
def self.header(type, token)
|
15
17
|
case token
|
16
|
-
when String, Symbol
|
18
|
+
when String, Symbol, Proc
|
19
|
+
token = token.call if token.is_a?(Proc)
|
17
20
|
"#{type} #{token}"
|
18
21
|
when Hash
|
19
22
|
build_hash(type.to_s, token)
|
@@ -32,6 +35,7 @@ module Faraday
|
|
32
35
|
comma = ', '
|
33
36
|
values = []
|
34
37
|
hash.each do |key, value|
|
38
|
+
value = value.call if value.is_a?(Proc)
|
35
39
|
values << "#{key}=#{value.to_s.inspect}"
|
36
40
|
end
|
37
41
|
"#{type} #{values * comma}"
|
@@ -39,16 +43,19 @@ module Faraday
|
|
39
43
|
|
40
44
|
# @param app [#call]
|
41
45
|
# @param type [String, Symbol] Type of Authorization
|
42
|
-
# @param
|
43
|
-
|
44
|
-
|
46
|
+
# @param param [String, Symbol, Hash, Proc] parameter to build the Authorization header.
|
47
|
+
# This value can be a proc, in which case it will be invoked on each request.
|
48
|
+
def initialize(app, type, param)
|
49
|
+
@type = type
|
50
|
+
@param = param
|
45
51
|
super(app)
|
46
52
|
end
|
47
53
|
|
48
54
|
# @param env [Faraday::Env]
|
49
|
-
def
|
50
|
-
|
51
|
-
|
55
|
+
def on_request(env)
|
56
|
+
return if env.request_headers[KEY]
|
57
|
+
|
58
|
+
env.request_headers[KEY] = self.class.header(@type, @param)
|
52
59
|
end
|
53
60
|
end
|
54
61
|
end
|
data/lib/faraday/version.rb
CHANGED
@@ -84,5 +84,13 @@ RSpec.describe Faraday::Request::Authorization do
|
|
84
84
|
|
85
85
|
include_examples 'does not interfere with existing authentication'
|
86
86
|
end
|
87
|
+
|
88
|
+
context 'when passed a string and a proc' do
|
89
|
+
let(:auth_config) { ['Bearer', -> { 'custom_from_proc' }] }
|
90
|
+
|
91
|
+
it { expect(response.body).to eq('Bearer custom_from_proc') }
|
92
|
+
|
93
|
+
include_examples 'does not interfere with existing authentication'
|
94
|
+
end
|
87
95
|
end
|
88
96
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "@technoweenie"
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-09-
|
13
|
+
date: 2021-09-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday-em_http
|
@@ -260,7 +260,7 @@ licenses:
|
|
260
260
|
- MIT
|
261
261
|
metadata:
|
262
262
|
homepage_uri: https://lostisland.github.io/faraday
|
263
|
-
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v1.
|
263
|
+
changelog_uri: https://github.com/lostisland/faraday/releases/tag/v1.8.0
|
264
264
|
source_code_uri: https://github.com/lostisland/faraday
|
265
265
|
bug_tracker_uri: https://github.com/lostisland/faraday/issues
|
266
266
|
post_install_message:
|