Skip to content

Commit

Permalink
add option to use secure url for image in auth hash [closes simi#36]
Browse files Browse the repository at this point in the history
  • Loading branch information
mkdynamic committed Mar 11, 2012
1 parent 46de6e7 commit c06341e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -36,6 +36,7 @@ You can configure several options, which you pass in to the `provider` method vi

* `scope`: A comma-separated list of permissions you want to request from the user. See the Facebook docs for a full list of available permissions: http://developers.facebook.com/docs/reference/api/permissions. Default: `email,offline_access`
* `display`: The display context to show the authentication page. Options are: `page`, `popup`, `iframe`, `touch` and `wap`. Read the Facebook docs for more details: http://developers.facebook.com/docs/reference/dialogs#display. Default: `page`
* `secure_image_url`: Set to `true` to use https for the avatar image url returned in the authentication hash. Default is `false`.

For example, to request `email`, `offline_access` and `read_stream` permissions and display the authentication page in a popup window:

Expand Down
2 changes: 1 addition & 1 deletion lib/omniauth/strategies/facebook.rb
Expand Up @@ -35,7 +35,7 @@ class NoAuthorizationCodeError < StandardError; end
'name' => raw_info['name'],
'first_name' => raw_info['first_name'],
'last_name' => raw_info['last_name'],
'image' => "http://graph.facebook.com/#{uid}/picture?type=square",
'image' => "#{options[:secure_image_url] ? 'https' : 'http'}://graph.facebook.com/#{uid}/picture?type=square",
'description' => raw_info['bio'],
'urls' => {
'Facebook' => raw_info['link'],
Expand Down
24 changes: 18 additions & 6 deletions spec/omniauth/strategies/facebook_spec.rb
Expand Up @@ -112,12 +112,12 @@
end

describe '#info' do
before :each do
@raw_info ||= { 'name' => 'Fred Smith' }
subject.stub(:raw_info) { @raw_info }
end

context 'when optional data is not present in raw info' do
before :each do
@raw_info ||= { 'name' => 'Fred Smith' }
subject.stub(:raw_info) { @raw_info }
end

it 'has no email key' do
subject.info.should_not have_key('email')
end
Expand Down Expand Up @@ -151,7 +151,12 @@
end
end

context 'when data is present in raw info' do
context 'when optional data is present in raw info' do
before :each do
@raw_info ||= { 'name' => 'Fred Smith' }
subject.stub(:raw_info) { @raw_info }
end

it 'returns the name' do
subject.info['name'].should eq('Fred Smith')
end
Expand Down Expand Up @@ -221,6 +226,13 @@
subject.info['verified'].should be_false
end
end

it 'returns the secure facebook avatar url when `secure_image_url` option is specified' do
@options = { :secure_image_url => true }
raw_info = { 'name' => 'Fred Smith', 'id' => '321' }
subject.stub(:raw_info) { raw_info }
subject.info['image'].should eq('https://graph.facebook.com/321/picture?type=square')
end
end

describe '#raw_info' do
Expand Down

0 comments on commit c06341e

Please sign in to comment.