Skip to content

Commit 1e13bcc

Browse files
committed
unfortunatelly, Apple returns weird success response..
1 parent df81cd7 commit 1e13bcc

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/omniauth/strategies/apple.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ def fetch_jwks
100100
end
101101
res = conn.get 'https://appleid.apple.com/auth/keys'
102102
if res.success?
103-
res.body
103+
jwks = res.body
104+
if jwks.is_a?(Hash)
105+
jwks
106+
else
107+
fail!(:jwks_fetching_failed, CallbackError.new(:jwks_fetching_failed, "Invalid format of JWKS returned: #{jwks}"))
108+
end
104109
else
105110
fail!(:jwks_fetching_failed, CallbackError.new(:jwks_fetching_failed, 'HTTP Error when fetching JWKs'))
106111
end

spec/omniauth/strategies/apple_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,5 +380,24 @@
380380
subject.info
381381
end
382382
end
383+
384+
context 'when JWKS format is missing :keys' do
385+
before do
386+
stub_request(:get, 'https://appleid.apple.com/auth/keys').to_return(
387+
body: 'true',
388+
headers: {
389+
'Content-Type': 'application/json'
390+
}
391+
)
392+
end
393+
394+
it do
395+
expect(subject).to receive(:fail!).with(
396+
:jwks_fetching_failed,
397+
instance_of(OmniAuth::Strategies::OAuth2::CallbackError)
398+
)
399+
subject.info
400+
end
401+
end
383402
end
384403
end

0 commit comments

Comments
 (0)