restforce 7.0.0 → 7.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +1 -1
- data/.github/workflows/faraday.yml +1 -1
- data/CHANGELOG.md +9 -0
- data/Gemfile +3 -3
- data/README.md +13 -2
- data/lib/restforce/concerns/authentication.rb +8 -0
- data/lib/restforce/error_code.rb +3 -0
- data/lib/restforce/middleware/authentication/client_credential.rb +15 -0
- data/lib/restforce/middleware/authentication.rb +1 -0
- data/lib/restforce/version.rb +1 -1
- data/restforce.gemspec +1 -1
- data/spec/unit/concerns/authentication_spec.rb +33 -0
- data/spec/unit/middleware/authentication/client_credential_spec.rb +36 -0
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a0ee639c5474908f899230f1e801aafa30e62d1314c04b52bca5f5ea842b8e1
|
4
|
+
data.tar.gz: a1c924d58834511b04be15063f912da17af5d5ac903b405151b4a82d3c47c5f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa8467ba371dc3643a76ca5310a8d003edd9342a326c74f1e70f996cc4abde457a9b5697a91c12ee87af7547c49ba382c936b41de56b5ec9703b1d8d44143841
|
7
|
+
data.tar.gz: b73dbcc4f08401e5c2ec79e486634a1ce6991197897e5aef2be077740072424213d97e16ba07b7f8c1b3015b0b344bb961af2f7803908202484f212d96c8535b
|
data/.github/workflows/build.yml
CHANGED
@@ -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.
|
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/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
# 7.1.1 (Jan 23, 2024)
|
2
|
+
|
3
|
+
- Handle the `APEX_REST_SERVICES_DISABLED` error returned by the Salesforce API
|
4
|
+
|
5
|
+
# 7.1.0 (Dec 20, 2023)
|
6
|
+
|
7
|
+
- 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)
|
8
|
+
- Add support for `faraday` v2.8.x (@timrogers)
|
9
|
+
|
1
10
|
# 7.0.0 (Oct 6, 2023)
|
2
11
|
|
3
12
|
__This version contains breaking changes. For help with upgrading, see [`UPGRADING.md`](https://github.com/restforce/restforce/blob/main/UPGRADING.md).__
|
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.
|
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.
|
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.
|
20
|
+
gem 'rubocop', '~> 1.60.1'
|
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', '~> 7.
|
30
|
+
gem 'restforce', '~> 7.1.1'
|
31
31
|
|
32
32
|
And then execute:
|
33
33
|
|
@@ -59,7 +59,7 @@ so you can do things like `client.query('select Id, (select Name from Children__
|
|
59
59
|
|
60
60
|
Which authentication method you use really depends on your use case. If you're
|
61
61
|
building an application where many users from different organizations are authenticated
|
62
|
-
through
|
62
|
+
through OAuth and you need to interact with data in their org on their behalf,
|
63
63
|
you should use the OAuth token authentication method.
|
64
64
|
|
65
65
|
If you're using the gem to interact with a single org (maybe you're building some
|
@@ -155,6 +155,17 @@ client = Restforce.new
|
|
155
155
|
|
156
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.
|
157
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
|
+
|
158
169
|
#### Sandbox Organizations
|
159
170
|
|
160
171
|
You can connect to sandbox organizations by specifying a host. The default host is
|
@@ -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
|
data/lib/restforce/error_code.rb
CHANGED
@@ -19,6 +19,8 @@ module Restforce
|
|
19
19
|
|
20
20
|
class ApexError < ResponseError; end
|
21
21
|
|
22
|
+
class ApexRestServicesDisabled < ResponseError; end
|
23
|
+
|
22
24
|
class ApiCurrentlyDisabled < ResponseError; end
|
23
25
|
|
24
26
|
class ApiDisabledForOrg < ResponseError; end
|
@@ -429,6 +431,7 @@ module Restforce
|
|
429
431
|
"ALL_OR_NONE_OPERATION_ROLLED_BACK" => AllOrNoneOperationRolledBack,
|
430
432
|
"ALREADY_IN_PROCESS" => AlreadyInProcess,
|
431
433
|
"APEX_ERROR" => ApexError,
|
434
|
+
"APEX_REST_SERVICES_DISABLED" => ApexRestServicesDisabled,
|
432
435
|
"API_CURRENTLY_DISABLED" => ApiCurrentlyDisabled,
|
433
436
|
"API_DISABLED_FOR_ORG" => ApiDisabledForOrg,
|
434
437
|
"ASSIGNEE_TYPE_REQUIRED" => AssigneeTypeRequired,
|
@@ -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.
|
data/lib/restforce/version.rb
CHANGED
data/restforce.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |gem|
|
|
24
24
|
|
25
25
|
gem.required_ruby_version = '>= 3.0'
|
26
26
|
|
27
|
-
gem.add_dependency 'faraday', '< 2.
|
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: 7.
|
4
|
+
version: 7.1.1
|
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:
|
12
|
+
date: 2024-01-23 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.
|
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.
|
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
|
@@ -293,7 +295,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
293
295
|
- !ruby/object:Gem::Version
|
294
296
|
version: '0'
|
295
297
|
requirements: []
|
296
|
-
rubygems_version: 3.
|
298
|
+
rubygems_version: 3.5.3
|
297
299
|
signing_key:
|
298
300
|
specification_version: 4
|
299
301
|
summary: A lightweight Ruby client for the Salesforce REST API
|