Skip to content

Commit 33ccf37

Browse files
authored
Merge pull request #98 from nov/feature/handle_unexpected_format_of_jwks_success_response
handle `fail!` in correct way
2 parents db3ae84 + eeaf084 commit 33ccf37

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

lib/omniauth/strategies/apple.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
module OmniAuth
77
module Strategies
88
class Apple < OmniAuth::Strategies::OAuth2
9+
class JWTFetchingFailed < CallbackError
10+
def initialize(error_reason = nil, error_uri = nil)
11+
super :jwks_fetching_failed, error_reason, error_uri
12+
end
13+
end
14+
915
option :name, 'apple'
1016

1117
option :client_options,
@@ -102,10 +108,10 @@ def fetch_jwks
102108
if res.success?
103109
res.body
104110
else
105-
fail!(:jwks_fetching_failed, CallbackError.new(:jwks_fetching_failed, 'HTTP Error when fetching JWKs'))
111+
raise JWTFetchingFailed.new('HTTP Error when fetching JWKs')
106112
end
107-
rescue Faraday::Error => e
108-
fail!(:jwks_fetching_failed, e)
113+
rescue JWTFetchingFailed, Faraday::Error => e
114+
fail!(:jwks_fetching_failed, e) and nil
109115
end
110116

111117
def verify_nonce!(payload)

spec/omniauth/strategies/apple_spec.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,10 @@
265265

266266
context 'fails nonce' do
267267
before(:each) do
268-
expect(subject).to receive(:fail!).with(:nonce_mismatch, instance_of(OmniAuth::Strategies::OAuth2::CallbackError))
268+
expect(subject).to receive(:fail!).with(
269+
:nonce_mismatch,
270+
instance_of(OmniAuth::Strategies::OAuth2::CallbackError)
271+
).and_return([302, {}, ''])
269272
end
270273
it 'when differs from session' do
271274
subject.session['omniauth.nonce'] = 'abc'
@@ -356,8 +359,8 @@
356359
it do
357360
expect(subject).to receive(:fail!).with(
358361
:jwks_fetching_failed,
359-
instance_of(OmniAuth::Strategies::OAuth2::CallbackError)
360-
)
362+
instance_of(OmniAuth::Strategies::Apple::JWTFetchingFailed)
363+
).and_return([302, {}, ''])
361364
subject.info
362365
end
363366
end
@@ -376,7 +379,7 @@
376379
expect(subject).to receive(:fail!).with(
377380
:jwks_fetching_failed,
378381
instance_of(Faraday::ParsingError)
379-
)
382+
).and_return([302, {}, ''])
380383
subject.info
381384
end
382385
end

0 commit comments

Comments
 (0)