Skip to content

Commit 0b5e2d6

Browse files
committed
Merge branch 'main' into gh-main
2 parents 9e90ff5 + cc38bf5 commit 0b5e2d6

File tree

9 files changed

+87
-1
lines changed

9 files changed

+87
-1
lines changed

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,27 @@ This is a RubyGem for implementing OAuth 2.0 clients (not servers) in Ruby appli
2424
[sibling-gem]: https://gitlab.com/oauth-xx/oauth
2525
[doorkeeper-gem]: https://github.com/doorkeeper-gem/doorkeeper
2626

27+
If this library has helped you, or your organization,
28+
please support my efforts by making a donation, becoming a sponsor, or giving me a shout on Mastodon.
29+
30+
[![Liberapay Patrons][⛳liberapay-img]][⛳liberapay]
31+
[![Sponsor Me on Github][🖇sponsor-img]][🖇sponsor]
32+
33+
<span class="badge-buymeacoffee">
34+
<a href="https://ko-fi.com/O5O86SNP4" target='_blank' title="Donate to my FLOSS or refugee efforts at ko-fi.com"><img src="https://img.shields.io/badge/buy%20me%20coffee-donate-yellow.svg" alt="Buy me coffee donation button" /></a>
35+
</span>
36+
<span class="badge-patreon">
37+
<a href="https://patreon.com/galtzo" title="Donate to my FLOSS or refugee efforts using Patreon"><img src="https://img.shields.io/badge/patreon-donate-yellow.svg" alt="Patreon donate button" /></a>
38+
</span>
39+
40+
<a rel="me" alt="Follow me on Ruby.social" href="https://ruby.social/@galtzo"><img src="https://img.shields.io/mastodon/follow/109447111526622197?domain=https%3A%2F%2Fruby.social&style=social&label=Follow%20%40galtzo%20on%20Ruby.social"></a>
41+
<a rel="me" alt="Follow me on FLOSS.social" href="https://floss.social/@galtzo"><img src="https://img.shields.io/mastodon/follow/110304921404405715?domain=https%3A%2F%2Ffloss.social&style=social&label=Follow%20%40galtzo%20on%20Floss.social"></a>
42+
43+
[⛳liberapay-img]: https://img.shields.io/liberapay/patrons/pboling.svg?logo=liberapay
44+
[⛳liberapay]: https://liberapay.com/pboling/donate
45+
[🖇sponsor-img]: https://img.shields.io/badge/Sponsor_Me!-pboling.svg?style=social&logo=github
46+
[🖇sponsor]: https://github.com/sponsors/pboling
47+
2748
## Release Documentation
2849

2950
### Version 2.0.x
@@ -310,7 +331,7 @@ See [SECURITY.md][🚎sec-pol]
310331

311332
### Global Configuration
312333

313-
If you started seeing this warning, but everything it working fine, you can now silence it.
334+
If you started seeing this warning, but everything is working fine, you can now silence it.
314335
```log
315336
OAuth2::AccessToken.from_hash: `hash` contained more than one 'token' key
316337
```

lib/oauth2.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
# includes gem files
1212
require 'oauth2/version'
13+
require 'oauth2/filtered_attributes'
1314
require 'oauth2/error'
1415
require 'oauth2/authenticator'
1516
require 'oauth2/client'

lib/oauth2/access_token.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ class AccessToken # rubocop:disable Metrics/ClassLength
66
TOKEN_KEYS_SYM = %i[access_token id_token token accessToken idToken].freeze
77
TOKEN_KEY_LOOKUP = TOKEN_KEYS_STR + TOKEN_KEYS_SYM
88

9+
include FilteredAttributes
10+
911
attr_reader :client, :token, :expires_in, :expires_at, :expires_latency, :params
1012
attr_accessor :options, :refresh_token, :response
13+
filtered_attributes :token, :refresh_token
1114

1215
class << self
1316
# Initializes an AccessToken from a Hash

lib/oauth2/authenticator.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
module OAuth2
66
class Authenticator
7+
include FilteredAttributes
8+
79
attr_reader :mode, :id, :secret
10+
filtered_attributes :secret
811

912
def initialize(id, secret, mode)
1013
@id = id

lib/oauth2/client.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ module OAuth2
1616
class Client # rubocop:disable Metrics/ClassLength
1717
RESERVED_PARAM_KEYS = %w[body headers params parse snaky].freeze
1818

19+
include FilteredAttributes
20+
1921
attr_reader :id, :secret, :site
2022
attr_accessor :options
2123
attr_writer :connection
24+
filtered_attributes :secret
2225

2326
# Instantiate a new OAuth 2.0 client using the
2427
# Client ID and Client Secret registered to your

lib/oauth2/filtered_attributes.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module OAuth2
2+
module FilteredAttributes
3+
def self.included(base)
4+
base.extend(ClassMethods)
5+
end
6+
7+
module ClassMethods
8+
def filtered_attributes(*attributes)
9+
@filtered_attribute_names = attributes.map(&:to_sym)
10+
end
11+
12+
def filtered_attribute_names
13+
@filtered_attribute_names || []
14+
end
15+
end
16+
17+
def inspect
18+
filtered_attribute_names = self.class.filtered_attribute_names
19+
return super if filtered_attribute_names.empty?
20+
21+
inspected_vars = instance_variables.map do |var|
22+
if filtered_attribute_names.any? { |filtered_var| var.to_s.include?(filtered_var.to_s) }
23+
"#{var}=[FILTERED]"
24+
else
25+
"#{var}=#{instance_variable_get(var).inspect}"
26+
end
27+
end
28+
"#<#{self.class}:#{object_id} #{inspected_vars.join(', ')}>"
29+
end
30+
end
31+
end

spec/oauth2/access_token_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,4 +741,16 @@ def self.contains_token?(hash)
741741
expect(access_token.to_hash).to eq(hash)
742742
end
743743
end
744+
745+
describe '#inspect' do
746+
let(:inspect_result) { described_class.new(nil, 'secret-token', { refresh_token: 'secret-refresh-token' }).inspect }
747+
748+
it 'filters out the @token value' do
749+
expect(inspect_result).to include('@token=[FILTERED]')
750+
end
751+
752+
it 'filters out the @refresh_token value' do
753+
expect(inspect_result).to include('@refresh_token=[FILTERED]')
754+
end
755+
end
744756
end

spec/oauth2/authenticator_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,10 @@
123123
end
124124
end
125125
end
126+
127+
describe '#inspect' do
128+
it 'filters out the @secret value' do
129+
expect(subject.inspect).to include('@secret=[FILTERED]')
130+
end
131+
end
126132
end

spec/oauth2/client_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,4 +967,10 @@ def stubbed_client(params = {}, &stubs)
967967
expect(subject.connection.builder.handlers).to include(Faraday::Request::UrlEncoded)
968968
end
969969
end
970+
971+
describe '#inspect' do
972+
it 'filters out the @secret value' do
973+
expect(subject.inspect).to include('@secret=[FILTERED]')
974+
end
975+
end
970976
end

0 commit comments

Comments
 (0)