Skip to content
This repository was archived by the owner on Jun 29, 2024. It is now read-only.

Commit 1f616b1

Browse files
committed
make the error handling when missing scope for reading user info better.
1 parent 124249e commit 1f616b1

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

lib/omniauth/strategies/zoom.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ def raw_info
3636
return @raw_info if defined?(@raw_info)
3737

3838
@raw_info = access_token.get('/v2/users/me').parsed || {}
39-
rescue StandardError => e
39+
rescue ::OAuth2::Error => e
40+
raise e unless e.response.status == 400
41+
42+
# in case of missing a scope for reading current user info
4043
log(:error, "#{e.class} occured. message:#{e.message}")
4144
@raw_info = {}
4245
end

test/omniauth/zoom_test.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_it_returns_auth_hash_in_callback_phase
3737

3838
def test_it_returns_auth_hash_in_case_of_failure_of_get_user_info_in_callbach_phase
3939
add_mock_exchange_token
40-
add_mock_user_info_then_fail
40+
add_mock_user_info_then_fail_because_of_missing_scope
4141
post '/auth/zoom/callback', :code => @authorization_code, :state => 'state123'
4242

4343
actual_auth = auth_hash.to_hash
@@ -52,6 +52,13 @@ def test_it_returns_auth_hash_in_case_of_failure_of_get_user_info_in_callbach_ph
5252
assert_equal(expected_auth, actual_auth)
5353
end
5454

55+
def test_it_does_not_return_auth_hash_in_case_of_unkonwn_failure_in_callbach_phase
56+
add_mock_exchange_token
57+
add_mock_user_info_then_fail_because_of_unknown
58+
post '/auth/zoom/callback', :code => @authorization_code, :state => 'state123'
59+
assert_nil(auth_hash)
60+
end
61+
5562
private
5663

5764
def auth_hash

test/test_helper.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def add_mock_user_info
6767
stub_request(:get, url).with(:headers => headers).to_return(:status => 200, :body => dummy_user_info_response.to_json, :headers => res_headers)
6868
end
6969

70-
def add_mock_user_info_then_fail
70+
def add_mock_user_info_then_fail_because_of_missing_scope
7171
WebMock.enable!
7272
url = 'https://zoom.us/v2/users/me'
7373
response = {:code => 124, :message => 'Invalid access token.'}
@@ -76,6 +76,15 @@ def add_mock_user_info_then_fail
7676
stub_request(:get, url).with(:headers => headers).to_return(:status => 400, :body => response.to_json, :headers => res_headers)
7777
end
7878

79+
def add_mock_user_info_then_fail_because_of_unknown
80+
WebMock.enable!
81+
url = 'https://zoom.us/v2/users/me'
82+
response = {:code => 999, :message => 'Unknown Error'}
83+
headers = {'Authorization' => "Bearer #{@access_token}"}
84+
res_headers = {'Content-Type' => 'application/json'}
85+
stub_request(:get, url).with(:headers => headers).to_return(:status => 500, :body => response.to_json, :headers => res_headers)
86+
end
87+
7988
def dummy_user_info_response
8089
{
8190
:id => 'KdYKjnimT4KPd8FFgQt9FQ',

0 commit comments

Comments
 (0)