diff --git a/lib/omniauth/strategies/mlh.rb b/lib/omniauth/strategies/mlh.rb index 0e48523..d39d0b9 100644 --- a/lib/omniauth/strategies/mlh.rb +++ b/lib/omniauth/strategies/mlh.rb @@ -74,9 +74,9 @@ def data def fetch_and_process_data response = access_token.get(build_api_url) data = JSON.parse(response.body, symbolize_names: true) - return {} unless data.is_a?(Hash) + return {} unless data.is_a?(Hash) && data[:data].is_a?(Hash) - symbolize_nested_arrays(data) + symbolize_nested_arrays(data[:data]) end def build_api_url diff --git a/spec/omni_auth/strategies/mlh_spec.rb b/spec/omni_auth/strategies/mlh_spec.rb index 974029a..b1234b3 100644 --- a/spec/omni_auth/strategies/mlh_spec.rb +++ b/spec/omni_auth/strategies/mlh_spec.rb @@ -13,7 +13,11 @@ end shared_context 'with oauth response' do |response_data| - let(:oauth_response) { instance_double(OAuth2::Response, parsed: { 'data' => response_data }) } + let(:oauth_response) do + instance_double(OAuth2::Response, + body: { 'data' => response_data }.to_json, + parsed: { 'data' => response_data }) + end before do allow(access_token).to receive(:get) .with('https://api.mlh.com/v4/users/me') @@ -23,7 +27,7 @@ describe '#data' do context 'with expandable fields' do - let(:response) { instance_double(OAuth2::Response, parsed: { 'data' => {} }) } + let(:response) { instance_double(OAuth2::Response, body: { 'data' => {} }.to_json, parsed: { 'data' => {} }) } let(:expand_url) { 'https://api.mlh.com/v4/users/me?expand[]=profile&expand[]=education' } before do