Skip to content

Commit 5387643

Browse files
authored
Merge pull request #666 from ruby-oauth/flat-params
2 parents 0610346 + d16d8a0 commit 5387643

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+320
-58
lines changed

.rubocop_gradual.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
[69, 15, 38, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 1480816240],
3535
[79, 13, 23, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 2314399065]
3636
],
37-
"spec/oauth2/client_spec.rb:292714281": [
37+
"spec/oauth2/client_spec.rb:2143306493": [
3838
[6, 1, 29, "RSpec/SpecFilePathFormat: Spec path should end with `o_auth2/client*_spec.rb`.", 439549885],
3939
[175, 7, 492, "RSpec/NoExpectationExample: No expectation found in this example.", 1272021224],
4040
[194, 7, 592, "RSpec/NoExpectationExample: No expectation found in this example.", 3428877205],

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
### Added
99
- improved documentation by @pboling
1010
- Document Mutual TLS (mTLS) usage with example in README (connection_opts.ssl client_cert/client_key and auth_scheme: :tls_client_auth)
11+
- Document usage of flat query params using Faraday::FlatParamsEncoder, with example URI, in README
12+
- Spec: verify flat params are preserved with Faraday::FlatParamsEncoder (skips on Faraday without FlatParamsEncoder)
1113
- documentation notes in code comments and README highlighting OAuth 2.1 differences, with references, such as:
1214
- PKCE required for auth code,
1315
- exact redirect URI match,

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,48 @@ client = OAuth2::Client.new(
991991
end
992992
```
993993

994+
##### Using flat query params (Faraday::FlatParamsEncoder)
995+
996+
Some APIs expect repeated key parameters to be sent as flat params rather than arrays. Faraday provides FlatParamsEncoder for this purpose. You can configure the oauth2 client to use it when building requests.
997+
998+
```ruby
999+
require "faraday"
1000+
1001+
client = OAuth2::Client.new(
1002+
id,
1003+
secret,
1004+
site: "https://api.example.com",
1005+
# Pass Faraday connection options to make FlatParamsEncoder the default
1006+
connection_opts: {
1007+
request: {params_encoder: Faraday::FlatParamsEncoder},
1008+
},
1009+
) do |faraday|
1010+
faraday.request(:url_encoded)
1011+
faraday.adapter(:net_http)
1012+
end
1013+
1014+
access = client.client_credentials.get_token
1015+
1016+
# Example of a GET with two flat filter params (not an array):
1017+
# Results in: ?filter=order.clientCreatedTime%3E1445006997000&filter=order.clientCreatedTime%3C1445611797000
1018+
resp = access.get(
1019+
"/v1/orders",
1020+
params: {
1021+
# Provide the values as an array; FlatParamsEncoder expands them as repeated keys
1022+
filter: [
1023+
"order.clientCreatedTime>1445006997000",
1024+
"order.clientCreatedTime<1445611797000",
1025+
],
1026+
},
1027+
)
1028+
```
1029+
1030+
If you instead need to build a raw Faraday connection yourself, the equivalent configuration is:
1031+
1032+
```ruby
1033+
conn = Faraday.new("https://api.example.com", request: {params_encoder: Faraday::FlatParamsEncoder})
1034+
```
1035+
9941036
#### Redirection
9951037

9961038
The library follows up to `max_redirects` (default 5).

docs/OAuth2.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ <h3 class="signature first" id="configure-class_method">
415415
</div>
416416

417417
<div id="footer">
418-
Generated on Sun Aug 31 04:29:08 2025 by
418+
Generated on Sun Aug 31 04:57:44 2025 by
419419
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
420420
0.9.37 (ruby-3.4.5).
421421
</div>

docs/OAuth2/AccessToken.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3069,7 +3069,7 @@ <h3 class="signature " id="to_hash-instance_method">
30693069
</div>
30703070

30713071
<div id="footer">
3072-
Generated on Sun Aug 31 04:29:08 2025 by
3072+
Generated on Sun Aug 31 04:57:44 2025 by
30733073
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
30743074
0.9.37 (ruby-3.4.5).
30753075
</div>

docs/OAuth2/Authenticator.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ <h3 class="signature first" id="apply-instance_method">
883883
</div>
884884

885885
<div id="footer">
886-
Generated on Sun Aug 31 04:29:08 2025 by
886+
Generated on Sun Aug 31 04:57:44 2025 by
887887
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
888888
0.9.37 (ruby-3.4.5).
889889
</div>

docs/OAuth2/Client.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2656,7 +2656,7 @@ <h3 class="signature " id="token_url-instance_method">
26562656
</div>
26572657

26582658
<div id="footer">
2659-
Generated on Sun Aug 31 04:29:08 2025 by
2659+
Generated on Sun Aug 31 04:57:44 2025 by
26602660
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
26612661
0.9.37 (ruby-3.4.5).
26622662
</div>

docs/OAuth2/Error.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ <h3 class="signature " id="response-instance_method">
772772
</div>
773773

774774
<div id="footer">
775-
Generated on Sun Aug 31 04:29:08 2025 by
775+
Generated on Sun Aug 31 04:57:44 2025 by
776776
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
777777
0.9.37 (ruby-3.4.5).
778778
</div>

docs/OAuth2/FilteredAttributes.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ <h3 class="signature first" id="inspect-instance_method">
335335
</div>
336336

337337
<div id="footer">
338-
Generated on Sun Aug 31 04:29:08 2025 by
338+
Generated on Sun Aug 31 04:57:44 2025 by
339339
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
340340
0.9.37 (ruby-3.4.5).
341341
</div>

docs/OAuth2/FilteredAttributes/ClassMethods.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ <h3 class="signature " id="filtered_attributes-instance_method">
280280
</div>
281281

282282
<div id="footer">
283-
Generated on Sun Aug 31 04:29:08 2025 by
283+
Generated on Sun Aug 31 04:57:44 2025 by
284284
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
285285
0.9.37 (ruby-3.4.5).
286286
</div>

0 commit comments

Comments
 (0)