Skip to content

Commit 8434f5a

Browse files
committed
Merge branch 'feat/docs-640' into 'main'
📝 Documentation See merge request oauth-xx/oauth2!644
2 parents 83aa50c + 5eb5fd7 commit 8434f5a

File tree

4 files changed

+57
-12
lines changed

4 files changed

+57
-12
lines changed

.rubocop_gradual.lock

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
{
2-
"README.md:620392337": [
3-
[305, 3, 1, "Layout/ClosingParenthesisIndentation: Indent `)` to column 0 (not 2)", 177548]
4-
],
52
"bin/bundle:3976421676": [
63
[66, 5, 20, "ThreadSafety/ClassInstanceVariable: Avoid class instance variables.", 2485198147],
74
[78, 5, 74, "Style/InvertibleUnlessCondition: Prefer `if Gem.rubygems_version >= Gem::Version.new(\"2.7.0\")` over `unless Gem.rubygems_version < Gem::Version.new(\"2.7.0\")`.", 2453573257]

CHANGELOG.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ and this project adheres to [Semantic Versioning v2](https://semver.org/spec/v2.
1212

1313
## [2.0.10] - 2025-05-12 ([tag][2.0.10t])
1414
### Added
15-
[!635](https://gitlab.com/oauth-xx/oauth2/-/merge_requests/635) - `.gitlab-ci.yml` file (@jessieay)
16-
- 20 year certificate for signing gem releases, expires 2045-04-29 (@pboling)
17-
- Gemspec metadata (@pboling)
18-
- funding_uri
19-
- news_uri
20-
- mailing_list_uri
21-
- SHA256 and SHA512 Checksums for release (@pboling)
15+
- [!635](https://gitlab.com/oauth-xx/oauth2/-/merge_requests/635) - `.gitlab-ci.yml` file (@jessieay)
16+
- [!643](https://gitlab.com/oauth-xx/oauth2/-/merge_requests/643) - Add token_name option (@pboling)
17+
- Specify the parameter name that identifies the access token
18+
- [!642](https://gitlab.com/oauth-xx/oauth2/-/merge_requests/642) - 20 year certificate for signing gem releases, expires 2045-04-29 (@pboling)
19+
- Gemspec metadata (@pboling)
20+
- funding_uri
21+
- news_uri
22+
- mailing_list_uri
23+
- SHA256 and SHA512 Checksums for release (@pboling)
24+
- [#638](https://gitlab.com/oauth-xx/oauth2/-/issues/638) - Documentation of support for ILO Fundamental Principles of Rights at Work
2225
### Changed
2326
- Gem releases are now cryptographically signed, with a 20-year cert (@pboling)
2427
- Allow linux distros to build release without signing, as their package managers sign independently
@@ -29,6 +32,10 @@ and this project adheres to [Semantic Versioning v2](https://semver.org/spec/v2.
2932
[!639](https://gitlab.com/oauth-xx/oauth2/-/merge_requests/639) - Only instantiate `OAuth2::Error` if `raise_errors` option is `true` (@glytch2)
3033
[!640](https://gitlab.com/oauth-xx/oauth2/-/merge_requests/640) - `README.md` documentation fix (@martinezcoder)
3134
[!641](https://gitlab.com/oauth-xx/oauth2/-/merge_requests/641) - Do not include sensitive information in the `inspect` (@manuelvanrijn)
35+
[#645](https://gitlab.com/oauth-xx/oauth2/-/issues/645) - Response no longer becomes a snaky hash (@pboling)
36+
[#639](https://gitlab.com/oauth-xx/oauth2/-/issues/639) - AccessToken#to_hash is now serializable, just a regular Hash (@pboling)
37+
[#95](https://gitlab.com/oauth-xx/oauth2/-/issues/95) - restoring an access token via `AccessToken#from_hash` (@pboling)
38+
- This was a 13 year old bug report. 😘
3239

3340
## [2.0.9] - 2022-09-16 ([tag][2.0.9t])
3441
### Added

README.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,34 @@ OAuth 2.0 focuses on client developer simplicity while providing specific author
4343
desktop applications, mobile phones, and living room devices.
4444
This is a RubyGem for implementing OAuth 2.0 clients (not servers) in Ruby applications.
4545

46+
Quick example: Convert the following `curl` command into a token request using this gem...
47+
48+
```shell
49+
curl --request POST \
50+
--url 'https://login.microsoftonline.com/REDMOND_REDACTED/oauth2/token' \
51+
--header 'content-type: application/x-www-form-urlencoded' \
52+
--data grant_type=client_credentials \
53+
--data client_id=REDMOND_CLIENT_ID \
54+
--data client_secret=REDMOND_CLIENT_SECRET \
55+
--data resource=REDMOND_RESOURCE_UUID
56+
```
57+
58+
NOTE: In the ruby version, certain params go in the get_token call, rather than in the client creation.
59+
60+
```ruby
61+
OAuth2::Client.new(
62+
"REDMOND_CLIENT_ID", # client_id
63+
"REDMOND_CLIENT_SECRET", # client_secret
64+
auth_scheme: :request_body, # Other modes are supported: :basic_auth, :tls_client_auth, :private_key_jwt
65+
token_url: "oauth2/token", # relative path, except with leading `/`, then absolute path
66+
site: "https://login.microsoftonline.com/REDMOND_REDACTED",
67+
). # The base path for token_url when it is relative
68+
client_credentials. # There are many other types to choose from!
69+
get_token(resource: "REDMOND_RESOURCE_UUID")
70+
```
71+
72+
NOTE: `header` - The content type specified in the `curl` is already the default!
73+
4674
## 💡 Info you can shake a stick at
4775

4876
* [OAuth 2.0 Spec][oauth2-spec]
@@ -265,6 +293,19 @@ OAuth2.configure do |config|
265293
end
266294
```
267295

296+
This comes from ambiguity in the spec about which token is the right token.
297+
Some OAuth 2.0 standards legitimately have multiple tokens.
298+
You may need to subclass `OAuth2::AccessToken`, or write your own custom alternative to it, and pass it in.
299+
Specify your custom class with the `access_token_class` option.
300+
301+
If you only need one token you can, as of v2.0.10,
302+
specify the exact token name you want to extract via the `OAuth2::AccessToken` using
303+
the `token_name` option.
304+
305+
You'll likely need to do some source diving.
306+
This gem has 100% test coverage for lines and branches, so the specs are a great place to look for ideas.
307+
If you have time and energy please contribute to the documentation!
308+
268309
### `authorize_url` and `token_url` are on site root (Just Works!)
269310

270311
```ruby
@@ -302,7 +343,7 @@ client = OAuth2::Client.new(
302343
site: "https://example.org/nested/directory/on/your/server",
303344
authorize_url: "/jaunty/authorize/",
304345
token_url: "/stirrups/access_token",
305-
)
346+
)
306347
# => #<OAuth2::Client:0x00000001204c8288 @id="client_id", @secret="client_sec...
307348
client.auth_code.authorize_url(redirect_uri: "http://localhost:8080/oauth2/callback")
308349
# => "https://example.org/jaunty/authorize/?client_id=client_id&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Foauth2%2Fcallback&response_type=code"

lib/oauth2/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Client # rubocop:disable Metrics/ClassLength
3636
# @option options [String] :authorize_url ('/oauth/authorize') absolute or relative URL path to the Authorization endpoint
3737
# @option options [String] :token_url ('/oauth/token') absolute or relative URL path to the Token endpoint
3838
# @option options [Symbol] :token_method (:post) HTTP method to use to request token (:get, :post, :post_with_query_string)
39-
# @option options [Symbol] :auth_scheme (:basic_auth) the authentication scheme (:basic_auth or :request_body)
39+
# @option options [Symbol] :auth_scheme (:basic_auth) the authentication scheme (:basic_auth, :request_body, :tls_client_auth, :private_key_jwt)
4040
# @option options [Hash] :connection_opts ({}) Hash of connection options to pass to initialize Faraday
4141
# @option options [Boolean] :raise_errors (true) whether to raise an OAuth2::Error on responses with 400+ status codes
4242
# @option options [Integer] :max_redirects (5) maximum number of redirects to follow

0 commit comments

Comments
 (0)