restforce 6.2.4 → 7.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: 5d97cb818f5a5a454ee219c4d0042a9fb3d39d410fdeebd1aefe07fd9787ddcf
4
- data.tar.gz: 584614d9bfd4f92b52c62476168cb974999bedd3406829516e75d66fd9f50d35
3
+ metadata.gz: fe63ad6684261df32867bad2431709006a8507a481261c14cd8fac1aab6dc88c
4
+ data.tar.gz: fe26e4ac42c9eda729b51d058f52a706d648673cf743b7fcf1f295747b41cd95
5
5
  SHA512:
6
- metadata.gz: da659c7c074a0a05b7839a3f28268a3c7c513d5e26a98f0fad80bc2d9c4f8dde9686eefdfce16b54609a41419820949750ef4a81505112c71f8203292ded3583
7
- data.tar.gz: c7b03f3ad45db1a83fc2f47c42e00761ca99c8f9a659b217bfaa9ac6d22deffc1346fb7024a87865c69cb658de30ca83d461a8a9db127be49bd6dfa32adb03c6
6
+ metadata.gz: 45e4800621600bc351f7cbe52bbb7847a89351a72c407d5de5cd01ecc2e99576ba2b8707f6ab47a8d95f09a1833934de63ff52b1867e0d4b640884683b2c1e85
7
+ data.tar.gz: 9aee02914b520b0f68c6d40017f136198e082db951a3a96af693da8537b963471b1ff4b73602588250bed6f8ba10d1c3a3a95eed118204c2c85f8913a178d3fb
@@ -6,7 +6,7 @@ jobs:
6
6
  strategy:
7
7
  fail-fast: false
8
8
  matrix:
9
- ruby_version: ['2.7', '3.0', '3.1', '3.2']
9
+ ruby_version: ['3.0', '3.1', '3.2']
10
10
  steps:
11
11
  - name: Checkout code
12
12
  uses: actions/checkout@v4
@@ -10,7 +10,7 @@ jobs:
10
10
  # For v2.0.x, we test v2.0.0 and v2.0.1 because v2.0.0 has a special behaviour where
11
11
  # the Net::HTTP adapter is not included. See
12
12
  # https://github.com/lostisland/faraday/blob/main/UPGRADING.md#faraday-20.
13
- faraday_version: ['1.1.0', '1.2.0', '1.3.1', '1.4.3', '1.5.1', '1.6.0', '1.7.2', '1.8.0', '1.9.3', '1.10.3', '2.0.0', '2.0.1', '2.1.0', '2.2.0', '2.3.0', '2.4.0', '2.5.2', '2.6.0', '2.7.4']
13
+ faraday_version: ['1.1.0', '1.2.0', '1.3.1', '1.4.3', '1.5.1', '1.6.0', '1.7.2', '1.8.0', '1.9.3', '1.10.3', '2.0.0', '2.0.1', '2.1.0', '2.2.0', '2.3.0', '2.4.0', '2.5.2', '2.6.0', '2.7.12', '2.8.0']
14
14
  env:
15
15
  FARADAY_VERSION: ~> ${{ matrix.faraday_version }}
16
16
  steps:
data/.rubocop.yml CHANGED
@@ -8,7 +8,7 @@ AllCops:
8
8
  - .*/**/*
9
9
  - vendor/**/*
10
10
  NewCops: enable
11
- TargetRubyVersion: 2.7
11
+ TargetRubyVersion: 3.0
12
12
 
13
13
  # Limit lines to 90 characters.
14
14
  Layout/LineLength:
data/CHANGELOG.md CHANGED
@@ -1,4 +1,15 @@
1
- # 6.2.4 (Oct 8, 2023)
1
+ # 7.1.0 (Dec 20, 2023)
2
+
3
+ - Add support for the [OAuth 2.0 Client Credentials authentication flow](https://help.salesforce.com/s/articleView?id=sf.remoteaccess_oauth_client_credentials_flow.htm&type=5) (@rh-taro)
4
+ - Add support for `faraday` v2.8.x (@timrogers)
5
+
6
+ # 7.0.0 (Oct 6, 2023)
7
+
8
+ __This version contains breaking changes. For help with upgrading, see [`UPGRADING.md`](https://github.com/restforce/restforce/blob/main/UPGRADING.md).__
9
+
10
+ * __⚠️ Drop support for Ruby 2.7__, since [Ruby 2.7 has reached its end-of-life](https://www.ruby-lang.org/en/downloads/) (@timrogers)
11
+
12
+ # 6.2.4 (Oct 6, 2023)
2
13
 
3
14
  * Register the custom JSON middleware for Faraday with a more unique name to avoid clashes with other middleware (@dbackeus)
4
15
 
data/Gemfile CHANGED
@@ -3,11 +3,11 @@
3
3
  source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
- faraday_version = ENV.fetch('FARADAY_VERSION', '~> 2.7.3')
6
+ faraday_version = ENV.fetch('FARADAY_VERSION', '~> 2.8.0')
7
7
 
8
8
  # Enable us to explicitly pick a Faraday version when running tests
9
9
  gem 'faraday', faraday_version
10
- gem 'faraday-typhoeus', '~> 1.0.0' unless faraday_version.start_with?("~> 1")
10
+ gem 'faraday-typhoeus', '~> 1.1.0' unless faraday_version.start_with?("~> 1")
11
11
  gem 'faye' unless RUBY_PLATFORM == 'java'
12
12
  gem 'guard-rspec'
13
13
  gem 'guard-rubocop'
@@ -17,6 +17,6 @@ gem 'rspec', '~> 3.12.0'
17
17
  gem 'rspec-collection_matchers', '~> 1.2.0'
18
18
  gem 'rspec-its', '~> 1.3.0'
19
19
  gem 'rspec_junit_formatter', '~> 0.6.0'
20
- gem 'rubocop', '~> 1.56.3'
20
+ gem 'rubocop', '~> 1.59.0'
21
21
  gem 'simplecov', '~> 0.22.0'
22
22
  gem 'webmock', '~> 3.19.1'
data/README.md CHANGED
@@ -27,7 +27,7 @@ Features include:
27
27
 
28
28
  Add this line to your application's Gemfile:
29
29
 
30
- gem 'restforce', '~> 6.2.4'
30
+ gem 'restforce', '~> 7.1.0'
31
31
 
32
32
  And then execute:
33
33
 
@@ -37,8 +37,9 @@ Or install it yourself as:
37
37
 
38
38
  $ gem install restforce
39
39
 
40
- __As of version 6.0.0, this gem is only compatible with Ruby 2.7.0 and later.__ If you're using an earlier Ruby version:
40
+ __As of version 7.0.0, this gem is only compatible with Ruby 3.0.0 and later.__ If you're using an earlier Ruby version:
41
41
 
42
+ * for Ruby 2.7, use version 6.2.4 or earlier
42
43
  * for Ruby 2.6, use version 5.3.1 or earlier
43
44
  * for Ruby 2.5, use version 5.0.6 or earlier
44
45
  * for Ruby 2.4, use version 4.3.0 or earlier
@@ -58,7 +59,7 @@ so you can do things like `client.query('select Id, (select Name from Children__
58
59
 
59
60
  Which authentication method you use really depends on your use case. If you're
60
61
  building an application where many users from different organizations are authenticated
61
- through oauth and you need to interact with data in their org on their behalf,
62
+ through OAuth and you need to interact with data in their org on their behalf,
62
63
  you should use the OAuth token authentication method.
63
64
 
64
65
  If you're using the gem to interact with a single org (maybe you're building some
@@ -154,6 +155,17 @@ client = Restforce.new
154
155
 
155
156
  **Note:** Restforce library does not cache JWT Bearer tokens automatically. This means that every instantiation of the Restforce class will be treated as a new login by Salesforce. Remember that Salesforce enforces [rate limits on login requests](https://help.salesforce.com/s/articleView?id=000312767&type=1). If you are building an application that will instantiate the Restforce class more than this specified rate limit, you might want to consider caching the Bearer token either in-memory or in your own storage by leveraging the `authentication_callback` method.
156
157
 
158
+ ## Client Credentials
159
+
160
+ If you want to authenticate as an application, you can use the [Client Credentials flow](https://help.salesforce.com/s/articleView?id=sf.remoteaccess_oauth_client_credentials_flow.htm&type=5):
161
+
162
+ ```ruby
163
+ client = Restforce.new(client_id: 'client_id',
164
+ client_secret: 'client_secret',
165
+ api_version: '55.0',
166
+ instance_url: 'instance_url')
167
+ ```
168
+
157
169
  #### Sandbox Organizations
158
170
 
159
171
  You can connect to sandbox organizations by specifying a host. The default host is
data/UPGRADING.md CHANGED
@@ -1,3 +1,15 @@
1
+ # Upgrading from Restforce 6.x to 7.x
2
+
3
+ ## Ruby 2.7 is no longer supported
4
+
5
+ __Likelyhood of impact__: Moderate
6
+
7
+ Ruby 2.7 is no longer officially supported as an active version of the Ruby language. That means that it will not receive patches and security fixes.
8
+
9
+ Accordingly, we've dropped support for Ruby 2.7 in the Restforce library. The gemspec now specifies that only 3.0 onwards is supported, and this will be enforced by RubyGems.
10
+
11
+ Before you update to Restforce 7.x, you'll need to switch to Ruby 3.0.0 or later. The current version of Ruby at the time of writing is 3.2.2.
12
+
1
13
  # Upgrading from Restforce 5.x to 6.x
2
14
 
3
15
  __There are two breaking changes introduced in Restforce 6.x__. In this guide, you'll learn about these changes and what you should check in your code to make sure that it will work with the latest version of the library.
@@ -21,6 +21,8 @@ module Restforce
21
21
  Restforce::Middleware::Authentication::Token
22
22
  elsif jwt?
23
23
  Restforce::Middleware::Authentication::JWTBearer
24
+ elsif client_credential?
25
+ Restforce::Middleware::Authentication::ClientCredential
24
26
  end
25
27
  end
26
28
 
@@ -48,6 +50,12 @@ module Restforce
48
50
  options[:username] &&
49
51
  options[:client_id]
50
52
  end
53
+
54
+ # Internal: Returns true if client credential flow should be used for
55
+ # authentication.
56
+ def client_credential?
57
+ options[:client_id] && options[:client_secret]
58
+ end
51
59
  end
52
60
  end
53
61
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Restforce
4
+ class Middleware
5
+ class Authentication
6
+ class ClientCredential < Restforce::Middleware::Authentication
7
+ def params
8
+ { grant_type: 'client_credentials',
9
+ client_id: @options[:client_id],
10
+ client_secret: @options[:client_secret] }
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -9,6 +9,7 @@ module Restforce
9
9
  autoload :Password, 'restforce/middleware/authentication/password'
10
10
  autoload :Token, 'restforce/middleware/authentication/token'
11
11
  autoload :JWTBearer, 'restforce/middleware/authentication/jwt_bearer'
12
+ autoload :ClientCredential, 'restforce/middleware/authentication/client_credential'
12
13
 
13
14
  # Rescue from 401's, authenticate then raise the error again so the client
14
15
  # can reissue the request.
@@ -31,7 +31,7 @@ module Restforce
31
31
  CONTENT_TYPE = 'Content-Type'
32
32
 
33
33
  MIME_TYPE = 'application/json'
34
- MIME_TYPE_REGEX = %r{^application/(vnd\..+\+)?json$}.freeze
34
+ MIME_TYPE_REGEX = %r{^application/(vnd\..+\+)?json$}
35
35
 
36
36
  #
37
37
  # Taken from `lib/faraday/middleware.rb` in the `faraday`
@@ -60,7 +60,7 @@ module Restforce
60
60
  }
61
61
  end
62
62
 
63
- ERROR_CODE_MATCHER = /\A[A-Z_]+\z/.freeze
63
+ ERROR_CODE_MATCHER = /\A[A-Z_]+\z/
64
64
 
65
65
  def exception_class_for_error_code(error_code)
66
66
  return Restforce::ResponseError unless ERROR_CODE_MATCHER.match?(error_code)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Restforce
4
- VERSION = '6.2.4'
4
+ VERSION = '7.1.0'
5
5
  end
data/restforce.gemspec CHANGED
@@ -22,9 +22,9 @@ Gem::Specification.new do |gem|
22
22
  'rubygems_mfa_required' => 'true'
23
23
  }
24
24
 
25
- gem.required_ruby_version = '>= 2.7'
25
+ gem.required_ruby_version = '>= 3.0'
26
26
 
27
- gem.add_dependency 'faraday', '< 2.8.0', '>= 1.1.0'
27
+ gem.add_dependency 'faraday', '< 2.9.0', '>= 1.1.0'
28
28
  gem.add_dependency 'faraday-follow_redirects', '<= 0.3.0', '< 1.0.0'
29
29
  gem.add_dependency 'faraday-multipart', '>= 1.0.0', '< 2.0.0'
30
30
  gem.add_dependency 'faraday-net_http', '< 4.0.0'
@@ -62,6 +62,17 @@ describe Restforce::Concerns::Authentication do
62
62
 
63
63
  it { should eq Restforce::Middleware::Authentication::JWTBearer }
64
64
  end
65
+
66
+ context 'when client_id and client_secret options are provided' do
67
+ before do
68
+ client.stub username_password?: false
69
+ client.stub oauth_refresh?: false
70
+ client.stub jwt?: false
71
+ client.stub client_credential?: true
72
+ end
73
+
74
+ it { should eq Restforce::Middleware::Authentication::ClientCredential }
75
+ end
65
76
  end
66
77
 
67
78
  describe '.username_password?' do
@@ -135,4 +146,26 @@ describe Restforce::Concerns::Authentication do
135
146
  it { should_not be true }
136
147
  end
137
148
  end
149
+
150
+ describe '.client_credential?' do
151
+ subject { client.client_credential? }
152
+ let(:options) { {} }
153
+
154
+ before do
155
+ client.stub options: options
156
+ end
157
+
158
+ context 'when oauth client credential options are provided' do
159
+ let(:options) do
160
+ { client_id: 'client',
161
+ client_secret: 'secret' }
162
+ end
163
+
164
+ it { should be_truthy }
165
+ end
166
+
167
+ context 'when oauth client credential options are not provided' do
168
+ it { should_not be true }
169
+ end
170
+ end
138
171
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Restforce::Middleware::Authentication::ClientCredential do
6
+ let(:options) do
7
+ { host: 'login.salesforce.com',
8
+ client_id: 'client_id',
9
+ client_secret: 'client_secret',
10
+ adapter: :net_http }
11
+ end
12
+
13
+ it_behaves_like 'authentication middleware' do
14
+ let(:success_request) do
15
+ stub_login_request(
16
+ body: "grant_type=client_credentials&" \
17
+ "client_id=client_id&client_secret=client_secret"
18
+ ).to_return(
19
+ status: 200,
20
+ body: fixture(:auth_success_response),
21
+ headers: { "Content-Type" => "application/json" }
22
+ )
23
+ end
24
+
25
+ let(:fail_request) do
26
+ stub_login_request(
27
+ body: "grant_type=client_credentials&" \
28
+ "client_id=client_id&client_secret=client_secret"
29
+ ).to_return(
30
+ status: 400,
31
+ body: fixture(:refresh_error_response),
32
+ headers: { "Content-Type" => "application/json" }
33
+ )
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.2.4
4
+ version: 7.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Rogers
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-10-06 00:00:00.000000000 Z
12
+ date: 2023-12-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -17,7 +17,7 @@ dependencies:
17
17
  requirements:
18
18
  - - "<"
19
19
  - !ruby/object:Gem::Version
20
- version: 2.8.0
20
+ version: 2.9.0
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
23
  version: 1.1.0
@@ -27,7 +27,7 @@ dependencies:
27
27
  requirements:
28
28
  - - "<"
29
29
  - !ruby/object:Gem::Version
30
- version: 2.8.0
30
+ version: 2.9.0
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.1.0
@@ -170,6 +170,7 @@ files:
170
170
  - lib/restforce/mash.rb
171
171
  - lib/restforce/middleware.rb
172
172
  - lib/restforce/middleware/authentication.rb
173
+ - lib/restforce/middleware/authentication/client_credential.rb
173
174
  - lib/restforce/middleware/authentication/jwt_bearer.rb
174
175
  - lib/restforce/middleware/authentication/password.rb
175
176
  - lib/restforce/middleware/authentication/token.rb
@@ -257,6 +258,7 @@ files:
257
258
  - spec/unit/document_spec.rb
258
259
  - spec/unit/error_code_spec.rb
259
260
  - spec/unit/mash_spec.rb
261
+ - spec/unit/middleware/authentication/client_credential_spec.rb
260
262
  - spec/unit/middleware/authentication/jwt_bearer_spec.rb
261
263
  - spec/unit/middleware/authentication/password_spec.rb
262
264
  - spec/unit/middleware/authentication/token_spec.rb
@@ -286,7 +288,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
286
288
  requirements:
287
289
  - - ">="
288
290
  - !ruby/object:Gem::Version
289
- version: '2.7'
291
+ version: '3.0'
290
292
  required_rubygems_version: !ruby/object:Gem::Requirement
291
293
  requirements:
292
294
  - - ">="