diff --git a/lib/omniauth/strategies/facebook.rb b/lib/omniauth/strategies/facebook.rb index 65c7dfc..567dc83 100644 --- a/lib/omniauth/strategies/facebook.rb +++ b/lib/omniauth/strategies/facebook.rb @@ -18,6 +18,16 @@ module OmniAuth } uid { raw_info['id'] } + + info { + { + 'nickname' => raw_info['username'], + 'email' => raw_info['email'], + 'first_name' => raw_info['first_name'], + 'last_name' => raw_info['last_name'], + 'image' => "http://graph.facebook.com/#{uid}/picture" + } + } def build_access_token super.tap do |token| diff --git a/spec/omniauth/strategies/facebook_spec.rb b/spec/omniauth/strategies/facebook_spec.rb index f6d8116..ca75a42 100644 --- a/spec/omniauth/strategies/facebook_spec.rb +++ b/spec/omniauth/strategies/facebook_spec.rb @@ -45,9 +45,44 @@ describe OmniAuth::Strategies::Facebook do end describe '#uid' do - it 'returns the id from raw_info' do + before :each do subject.stub(:raw_info) { { 'id' => '123' } } + end + + it 'returns the id from raw_info' do subject.uid.should eq('123') end end + + describe '#info' do + before :each do + @raw_info ||= {} + subject.stub(:raw_info) { @raw_info } + end + + it 'returns the username as nickname' do + @raw_info['username'] = 'fredsmith' + subject.info['nickname'].should eq('fredsmith') + end + + it 'returns the email' do + @raw_info['email'] = 'fred@smith.com' + subject.info['email'].should eq('fred@smith.com') + end + + it 'returns the first name' do + @raw_info['first_name'] = 'Fred' + subject.info['first_name'].should eq('Fred') + end + + it 'returns the last name' do + @raw_info['last_name'] = 'Smith' + subject.info['last_name'].should eq('Smith') + end + + it 'returns the facebook avatar url' do + @raw_info['id'] = '321' + subject.info['image'].should eq('http://graph.facebook.com/321/picture') + end + end end