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:
commit
9e7b85564f
3 changed files with 9 additions and 4 deletions
|
@ -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`.
|
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`.
|
* `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.
|
* `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:
|
For example, to request `email`, `user_birthday` and `read_stream` permissions and display the authentication page in a popup window:
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,11 @@ module OmniAuth
|
||||||
end
|
end
|
||||||
|
|
||||||
def raw_info
|
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
|
end
|
||||||
|
|
||||||
def build_access_token
|
def build_access_token
|
||||||
|
|
|
@ -256,7 +256,7 @@ class RawInfoTest < StrategyTestCase
|
||||||
|
|
||||||
test 'performs a GET to https://graph.facebook.com/me' do
|
test 'performs a GET to https://graph.facebook.com/me' do
|
||||||
strategy.stubs(:access_token).returns(@access_token)
|
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
|
strategy.raw_info
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -267,7 +267,7 @@ class RawInfoTest < StrategyTestCase
|
||||||
raw_response.stubs(:status).returns(200)
|
raw_response.stubs(:status).returns(200)
|
||||||
raw_response.stubs(:headers).returns({'Content-Type' => 'application/json' })
|
raw_response.stubs(:headers).returns({'Content-Type' => 'application/json' })
|
||||||
oauth2_response = OAuth2::Response.new(raw_response)
|
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_kind_of Hash, strategy.raw_info
|
||||||
assert_equal 'thar', strategy.raw_info['ohai']
|
assert_equal 'thar', strategy.raw_info['ohai']
|
||||||
end
|
end
|
||||||
|
@ -275,7 +275,7 @@ class RawInfoTest < StrategyTestCase
|
||||||
test 'returns an empty hash when the response is false' do
|
test 'returns an empty hash when the response is false' do
|
||||||
strategy.stubs(:access_token).returns(@access_token)
|
strategy.stubs(:access_token).returns(@access_token)
|
||||||
oauth2_response = stub('OAuth2::Response', :parsed => false)
|
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
|
assert_kind_of Hash, strategy.raw_info
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue