request_signing-faraday 0.1.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/request_signing/faraday.rb +70 -0
  3. metadata +74 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d9acdff23a9fb980fd7733b68908e6e85e89edf2
4
+ data.tar.gz: 05bb06eb5c6c585d6543ffd0a1b6ca18a02f54cc
5
+ SHA512:
6
+ metadata.gz: 9317dc9591893c503036fcc017dbaa7fe2cdf66a0ec85d76ea37cbe0e7c9a927de93143ffcb1c99cdfac06858518646cbde3b695b9b04a5eb77ba45f6603292f
7
+ data.tar.gz: 6d7a6aea777385f6c12f997b491ea87f15585ffbea8fce43d0bbf399664c01a5b0df9ecbbcd5d39babcebfc13cb3e5a37bbc33e20919e42a12c09df26df466d4
@@ -0,0 +1,70 @@
1
+ require 'faraday'
2
+ require "request_signing"
3
+
4
+ module RequestSigning
5
+ module Adapters
6
+
7
+ # Registers `:faraday` adapter for user with {RequestSigning::Signer}
8
+ #
9
+ # @example
10
+ # v = RequestSigning::Signer.new(adapter: :faraday, key_store: key_store)
11
+ class Faraday
12
+ def call(faraday_env)
13
+ GenericHTTPRequest.new(
14
+ faraday_env.method.to_s,
15
+ faraday_env.url.request_uri,
16
+ faraday_env.request_headers.map do |h, v|
17
+ [h.downcase, Array(v)]
18
+ end
19
+ )
20
+ end
21
+ end
22
+ end
23
+ register_adapter :faraday, ->() { Adapters::Faraday.new }
24
+
25
+ module Faraday
26
+
27
+ ##
28
+ # Provides faraday request middleware for request signing
29
+ #
30
+ # @example
31
+ # key_store = RequestSigning::KeyStores::Static.new(
32
+ # "app_1.v1" => ENV["APP_1_SECRET"],
33
+ # "app_2.v1" => ENV["APP_2_SECRET"],
34
+ # )
35
+ # conn = Faraday.new(url: "http://example.com") do |builder|
36
+ # builder.request :request_signing, key_store: key_store, key_id: "app_1.v1", algorithm: "hmac-sha256", headers: %w[(request-target) date x-user-id]
37
+ # builder.adapter :net_http
38
+ # end
39
+ #
40
+ # conn.post("/foo") do |req|
41
+ # req.headers["x-user-id"] = "42"
42
+ # end
43
+ ##
44
+ class Middleware < ::Faraday::Middleware
45
+
46
+ ##
47
+ # @param key_store (see RequestSigning::Signer#initialize)
48
+ # @param key_id (see RequestSigning::Signer#create_signature!)
49
+ # @param algorithm (see RequestSigning::Signer#create_signature!)
50
+ # @param headers (see RequestSigning::Signer#create_signature!)
51
+ # @raise (see RequestSigning::Signer#create_signature!)
52
+ ##
53
+ def initialize(app, key_store:, key_id:, algorithm: , headers: %w[date])
54
+ super(app)
55
+ @key_id = key_id
56
+ @algorithm = algorithm
57
+ @headers = headers
58
+ @signer = RequestSigning::Signer.new(adapter: :faraday, key_store: key_store)
59
+ end
60
+
61
+ def call(env)
62
+ env.request_headers["Date"] ||= Time.now.httpdate
63
+ env.request_headers["Signature"] = @signer.create_signature!(env, key_id: @key_id, algorithm: @algorithm, headers: @headers).to_s
64
+ @app.call(env)
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ Faraday::Request.register_middleware :request_signing => RequestSigning::Faraday::Middleware
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: request_signing-faraday
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre1
5
+ platform: ruby
6
+ authors:
7
+ - Vlad Yarotsky
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: request_signing
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0.pre1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0.pre1
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
41
+ description: Faraday middleware for request signing
42
+ email:
43
+ - vlad@remind101.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/request_signing/faraday.rb
49
+ homepage: https://github.com/remind101/request_signing
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ yard.run: yri
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">"
66
+ - !ruby/object:Gem::Version
67
+ version: 1.3.1
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 2.6.8
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Faraday middleware for request signing
74
+ test_files: []