1
0
Fork 0
mirror of https://github.com/simi/omniauth-facebook.git synced 2022-11-09 12:32:45 -05:00

Merge pull request #109 from bloudermilk/info_fields

Adds info_fields option
This commit is contained in:
Mark Dodwell 2013-05-10 23:51:46 -07:00
commit 9e7b85564f
3 changed files with 9 additions and 4 deletions

View file

@ -38,6 +38,7 @@ You can configure several options, which you pass in to the `provider` method vi
Valid values are `https` (checks for the presence of the secure cookie and asks for re-authentication if it is not present), and `reauthenticate` (asks the user to re-authenticate unconditionally). Default is `nil`.
* `secure_image_url`: Set to `true` to use https for the avatar image url returned in the auth hash. Default is `false`.
* `image_size`: Set the size for the returned image url in the auth hash. Valid options include `square` (50x50), `small` (50 pixels wide, variable height), `normal` (100 pixels wide, variable height), or `large` (about 200 pixels wide, variable height). Additionally, you can request a picture of a specific size by setting this option to a hash with `:width` and `:height` as keys. This will return an available profile picture closest to the requested size and requested aspect ratio. If only `:width` or `:height` is specified, we will return a picture whose width or height is closest to the requested size, respectively.
* `info_fields`: Specify exactly which fields should be returned when getting the user's info. Value should be a comma-separated string as per https://developers.facebook.com/docs/reference/api/user/.
For example, to request `email`, `user_birthday` and `read_stream` permissions and display the authentication page in a popup window:

View file

@ -54,7 +54,11 @@ module OmniAuth
end
def raw_info
@raw_info ||= access_token.get('/me').parsed || {}
@raw_info ||= access_token.get('/me', info_options).parsed || {}
end
def info_options
options[:info_fields] ? {:params => {:fields => options[:info_fields]}} : {}
end
def build_access_token

View file

@ -256,7 +256,7 @@ class RawInfoTest < StrategyTestCase
test 'performs a GET to https://graph.facebook.com/me' do
strategy.stubs(:access_token).returns(@access_token)
@access_token.expects(:get).with('/me').returns(stub_everything('OAuth2::Response'))
@access_token.expects(:get).with('/me', {}).returns(stub_everything('OAuth2::Response'))
strategy.raw_info
end
@ -267,7 +267,7 @@ class RawInfoTest < StrategyTestCase
raw_response.stubs(:status).returns(200)
raw_response.stubs(:headers).returns({'Content-Type' => 'application/json' })
oauth2_response = OAuth2::Response.new(raw_response)
@access_token.stubs(:get).with('/me').returns(oauth2_response)
@access_token.stubs(:get).with('/me', {}).returns(oauth2_response)
assert_kind_of Hash, strategy.raw_info
assert_equal 'thar', strategy.raw_info['ohai']
end
@ -275,7 +275,7 @@ class RawInfoTest < StrategyTestCase
test 'returns an empty hash when the response is false' do
strategy.stubs(:access_token).returns(@access_token)
oauth2_response = stub('OAuth2::Response', :parsed => false)
@access_token.stubs(:get).with('/me').returns(oauth2_response)
@access_token.stubs(:get).with('/me', {}).returns(oauth2_response)
assert_kind_of Hash, strategy.raw_info
end