stripe 8.6.0.pre.beta.2 → 8.6.0.pre.beta.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/Gemfile +1 -2
- data/OPENAPI_VERSION +1 -1
- data/VERSION +1 -1
- data/lib/stripe/request_signing_authenticator.rb +83 -0
- data/lib/stripe/stripe_client.rb +16 -3
- data/lib/stripe/stripe_configuration.rb +1 -0
- data/lib/stripe/util.rb +8 -1
- data/lib/stripe/version.rb +1 -1
- data/lib/stripe.rb +3 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8329baf2324481281bac8a14057e933252bcc1fccbde79f4303fb1e84d113c9
|
4
|
+
data.tar.gz: bce0345d4c34fb1b25278e55a5ca31db6303d7b5b69037d05e55b3aa8f68537e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7055e66eae45c2a9e3cf0d3dd6f65c1da2e7ef6a0189feb9a7cbf04de25b857a37e7888c7cfe8f391004192c9cbce4f3f30ee25236fa2f94bd4b7d4263ae696a
|
7
|
+
data.tar.gz: 47077ba02bc7c0c73071d92500333e84bce73cae25ea88ec0ff5c47b378bc5b2e0473cb5bc8cdc9d65d9151b6f74f5361df674685af2ce194d452ae0fe6d5df7
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 8.6.0-beta.3 - 2023-04-17
|
4
|
+
* [#1211](https://github.com/stripe/stripe-ruby/pull/1211) Update generated code for beta
|
5
|
+
* [#1210](https://github.com/stripe/stripe-ruby/pull/1210), [#1212](https://github.com/stripe/stripe-ruby/pull/1212), [#1213](https://github.com/stripe/stripe-ruby/pull/1213) Add support for request signing
|
6
|
+
|
3
7
|
## 8.6.0-beta.2 - 2023-04-13
|
4
8
|
* [#1206](https://github.com/stripe/stripe-ruby/pull/1206) Update generated code for beta
|
5
9
|
* Add support for `collect_payment_method` and `confirm_payment_intent` methods on resource `Terminal.Reader`
|
@@ -12,7 +16,7 @@
|
|
12
16
|
|
13
17
|
## 8.5.0 - 2023-03-30
|
14
18
|
* [#1203](https://github.com/stripe/stripe-ruby/pull/1203) Update generated code
|
15
|
-
* Remove support for `create` method on resource `Tax.Transaction`
|
19
|
+
* Remove support for `create` method on resource `Tax.Transaction`
|
16
20
|
* This is not a breaking change, as this method was deprecated before the Tax Transactions API was released in favor of the `create_from_calculation` method.
|
17
21
|
* [#1201](https://github.com/stripe/stripe-ruby/pull/1201) Update save deprecation message
|
18
22
|
|
data/Gemfile
CHANGED
data/OPENAPI_VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
v299
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
8.6.0-beta.
|
1
|
+
8.6.0-beta.3
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Stripe
|
4
|
+
class RequestSigningAuthenticator
|
5
|
+
AUTHORIZATION_HEADER_NAME = "Authorization"
|
6
|
+
CONTENT_TYPE_HEADER_NAME = "Content-Type"
|
7
|
+
STRIPE_CONTEXT_HEADER_NAME = "Stripe-Context"
|
8
|
+
STRIPE_ACCOUNT_HEADER_NAME = "Stripe-Account"
|
9
|
+
CONTENT_DIGEST_HEADER_NAME = "Content-Digest"
|
10
|
+
SIGNATURE_INPUT_HEADER_NAME = "Signature-Input"
|
11
|
+
SIGNATURE_HEADER_NAME = "Signature"
|
12
|
+
|
13
|
+
attr_reader :auth_token, :sign_lambda
|
14
|
+
|
15
|
+
def initialize(auth_token, sign_lambda)
|
16
|
+
unless auth_token.is_a?(String)
|
17
|
+
raise ArgumentError, "auth_token must be a string"
|
18
|
+
end
|
19
|
+
unless sign_lambda.is_a?(Proc)
|
20
|
+
raise ArgumentError, "sign_lambda must be a lambda"
|
21
|
+
end
|
22
|
+
|
23
|
+
@auth_token = auth_token
|
24
|
+
@sign_lambda = sign_lambda
|
25
|
+
end
|
26
|
+
|
27
|
+
def authenticate(method, headers, body)
|
28
|
+
covered_headers = [CONTENT_TYPE_HEADER_NAME,
|
29
|
+
CONTENT_DIGEST_HEADER_NAME,
|
30
|
+
STRIPE_CONTEXT_HEADER_NAME,
|
31
|
+
STRIPE_ACCOUNT_HEADER_NAME,
|
32
|
+
AUTHORIZATION_HEADER_NAME,]
|
33
|
+
|
34
|
+
headers[AUTHORIZATION_HEADER_NAME] = "STRIPE-V2-SIG #{auth_token}"
|
35
|
+
|
36
|
+
if method == :get
|
37
|
+
covered_headers -= [CONTENT_TYPE_HEADER_NAME,
|
38
|
+
CONTENT_DIGEST_HEADER_NAME,]
|
39
|
+
else
|
40
|
+
content = body || ""
|
41
|
+
headers[CONTENT_DIGEST_HEADER_NAME] =
|
42
|
+
%(sha-256=:#{content_digest(content)}:)
|
43
|
+
end
|
44
|
+
|
45
|
+
covered_headers_formatted = covered_headers
|
46
|
+
.map { |string| %("#{string.downcase}") }
|
47
|
+
.join(" ")
|
48
|
+
|
49
|
+
signature_input = "(#{covered_headers_formatted});created=#{created_time}"
|
50
|
+
|
51
|
+
inputs = covered_headers
|
52
|
+
.map { |header| %("#{header.downcase}": #{headers[header]}) }
|
53
|
+
.join("\n")
|
54
|
+
|
55
|
+
signature_base = %(#{inputs}\n"@signature-params": #{signature_input})
|
56
|
+
.encode(Encoding::UTF_8)
|
57
|
+
|
58
|
+
headers[SIGNATURE_INPUT_HEADER_NAME] = "sig1=#{signature_input}"
|
59
|
+
|
60
|
+
headers[SIGNATURE_HEADER_NAME] =
|
61
|
+
"sig1=:#{encoded_signature(signature_base)}:"
|
62
|
+
end
|
63
|
+
|
64
|
+
private def sign(signature_base)
|
65
|
+
@sign_lambda.call(signature_base)
|
66
|
+
end
|
67
|
+
|
68
|
+
private def encoded_signature(signature_base)
|
69
|
+
Base64.strict_encode64(sign(signature_base))
|
70
|
+
rescue StandardError
|
71
|
+
raise AuthenticationError, "Encountered '#{e.message} (#{e.class})' "\
|
72
|
+
"when calculating request signature."
|
73
|
+
end
|
74
|
+
|
75
|
+
private def content_digest(content)
|
76
|
+
Base64.strict_encode64(OpenSSL::Digest.new("SHA256").digest(content))
|
77
|
+
end
|
78
|
+
|
79
|
+
private def created_time
|
80
|
+
Time.now.to_i
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/lib/stripe/stripe_client.rb
CHANGED
@@ -440,9 +440,10 @@ module Stripe
|
|
440
440
|
|
441
441
|
api_base ||= config.api_base
|
442
442
|
api_key ||= config.api_key
|
443
|
+
authenticator ||= config.authenticator
|
443
444
|
params = Util.objects_to_ids(params)
|
444
445
|
|
445
|
-
|
446
|
+
check_keys!(api_key, authenticator)
|
446
447
|
|
447
448
|
body_params = nil
|
448
449
|
query_params = nil
|
@@ -469,11 +470,14 @@ module Stripe
|
|
469
470
|
body, body_log =
|
470
471
|
body_params ? encode_body(body_params, headers) : [nil, nil]
|
471
472
|
|
473
|
+
authenticator.authenticate(method, headers, body) unless api_key
|
474
|
+
|
472
475
|
# stores information on the request we're about to make so that we don't
|
473
476
|
# have to pass as many parameters around for logging.
|
474
477
|
context = RequestLogContext.new
|
475
478
|
context.account = headers["Stripe-Account"]
|
476
479
|
context.api_key = api_key
|
480
|
+
context.authenticator = authenticator
|
477
481
|
context.api_version = headers["Stripe-Version"]
|
478
482
|
context.body = body_log
|
479
483
|
context.idempotency_key = headers["Idempotency-Key"]
|
@@ -512,8 +516,16 @@ module Stripe
|
|
512
516
|
(api_base || config.api_base) + url
|
513
517
|
end
|
514
518
|
|
515
|
-
private def
|
516
|
-
|
519
|
+
private def check_keys!(api_key, authenticator)
|
520
|
+
if api_key && authenticator
|
521
|
+
raise AuthenticationError, "Can't specify both API key " \
|
522
|
+
"and authenticator. Either set your API key" \
|
523
|
+
'using "Stripe.api_key = <API-KEY>", or set your authenticator ' \
|
524
|
+
'using "Stripe.authenticator = <AUTHENTICATOR>"' \
|
525
|
+
end
|
526
|
+
|
527
|
+
unless api_key || authenticator
|
528
|
+
# Default to missing API key error message for general users.
|
517
529
|
raise AuthenticationError, "No API key provided. " \
|
518
530
|
'Set your API key using "Stripe.api_key = <API-KEY>". ' \
|
519
531
|
"You can generate API keys from the Stripe web interface. " \
|
@@ -966,6 +978,7 @@ module Stripe
|
|
966
978
|
attr_accessor :body
|
967
979
|
attr_accessor :account
|
968
980
|
attr_accessor :api_key
|
981
|
+
attr_accessor :authenticator
|
969
982
|
attr_accessor :api_version
|
970
983
|
attr_accessor :idempotency_key
|
971
984
|
attr_accessor :method
|
data/lib/stripe/util.rb
CHANGED
@@ -7,6 +7,7 @@ module Stripe
|
|
7
7
|
# Options that a user is allowed to specify.
|
8
8
|
OPTS_USER_SPECIFIED = Set[
|
9
9
|
:api_key,
|
10
|
+
:authenticator,
|
10
11
|
:idempotency_key,
|
11
12
|
:stripe_account,
|
12
13
|
:stripe_version
|
@@ -281,7 +282,13 @@ module Stripe
|
|
281
282
|
when String
|
282
283
|
{ api_key: opts }
|
283
284
|
when Hash
|
284
|
-
|
285
|
+
# If the user is using request signing for authentication,
|
286
|
+
# no need to check the api_key per request.
|
287
|
+
if !(opts.key?(:client) &&
|
288
|
+
opts.fetch(:client).config.authenticator) &&
|
289
|
+
opts.key?(:api_key)
|
290
|
+
check_api_key!(opts.fetch(:api_key))
|
291
|
+
end
|
285
292
|
# Explicitly use dup here instead of clone to avoid preserving freeze
|
286
293
|
# state on input params.
|
287
294
|
opts.dup
|
data/lib/stripe/version.rb
CHANGED
data/lib/stripe.rb
CHANGED
@@ -13,6 +13,7 @@ require "set"
|
|
13
13
|
require "socket"
|
14
14
|
require "uri"
|
15
15
|
require "forwardable"
|
16
|
+
require "base64"
|
16
17
|
|
17
18
|
# Version
|
18
19
|
require "stripe/api_version"
|
@@ -44,6 +45,7 @@ require "stripe/api_resource_test_helpers"
|
|
44
45
|
require "stripe/singleton_api_resource"
|
45
46
|
require "stripe/webhook"
|
46
47
|
require "stripe/stripe_configuration"
|
48
|
+
require "stripe/request_signing_authenticator"
|
47
49
|
|
48
50
|
# Named API resources
|
49
51
|
require "stripe/resources"
|
@@ -70,6 +72,7 @@ module Stripe
|
|
70
72
|
|
71
73
|
# User configurable options
|
72
74
|
def_delegators :@config, :api_key, :api_key=
|
75
|
+
def_delegators :@config, :authenticator, :authenticator=
|
73
76
|
def_delegators :@config, :api_version, :api_version=
|
74
77
|
def_delegators :@config, :stripe_account, :stripe_account=
|
75
78
|
def_delegators :@config, :api_base, :api_base=
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stripe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 8.6.0.pre.beta.
|
4
|
+
version: 8.6.0.pre.beta.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stripe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Stripe is the easiest way to accept payments online. See https://stripe.com
|
14
14
|
for details.
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- lib/stripe/multipart_encoder.rb
|
51
51
|
- lib/stripe/oauth.rb
|
52
52
|
- lib/stripe/object_types.rb
|
53
|
+
- lib/stripe/request_signing_authenticator.rb
|
53
54
|
- lib/stripe/resources.rb
|
54
55
|
- lib/stripe/resources/account.rb
|
55
56
|
- lib/stripe/resources/account_link.rb
|