Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5e20fdd

Browse files
2.0.6 uses different token to 2.0.5 (#626)
* Prefer the key order from the lookup, not the hash keys * Fix subject cop * Fix hash style cop
1 parent 86a686e commit 5e20fdd

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

‎lib/oauth2/access_token.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class << self
1818
# @return [AccessToken] the initialized AccessToken
1919
def from_hash(client, hash)
2020
fresh = hash.dup
21-
supported_keys = fresh.keys & TOKEN_KEY_LOOKUP
21+
supported_keys = TOKEN_KEY_LOOKUP & fresh.keys
2222
key = supported_keys[0]
2323
# Having too many is sus, and may lead to bugs. Having none is fine (e.g. refresh flow doesn't need a token).
2424
warn("OAuth2::AccessToken.from_hash: `hash` contained more than one 'token' key (#{supported_keys}); using #{key.inspect}.") if supported_keys.length > 1

‎spec/oauth2/access_token_spec.rb‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,28 @@
5353
expect(printed).to eq(msg)
5454
end
5555
end
56+
57+
context 'with keys in a different order to the lookup' do
58+
subject(:printed) do
59+
capture(:stderr) do
60+
target
61+
end
62+
end
63+
64+
let(:hash) do
65+
{
66+
id_token: 'confusing bug here',
67+
access_token: token,
68+
}
69+
end
70+
71+
it 'warns on STDERR and selects the correct key' do
72+
msg = <<-MSG.lstrip
73+
OAuth2::AccessToken.from_hash: `hash` contained more than one 'token' key ([:access_token, :id_token]); using :access_token.
74+
MSG
75+
expect(printed).to eq(msg)
76+
end
77+
end
5678
end
5779

5880
describe '#initialize' do

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /