omniauth-facebook 2.0.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 260633e199c78445cef2c7490799eccf267750cc
4
- data.tar.gz: ae89d1f7b067443f94929e2a897686ef95f5adc6
3
+ metadata.gz: 224e91c8d4a4c7c48c231c2f78984cd0cfe1c307
4
+ data.tar.gz: 49914f654b85df17a35c191dc7e9ee34cebf596f
5
5
  SHA512:
6
- metadata.gz: b89ed9dbbdf85294d20dbd318cd00f1120a0c6cabbc641c60e96cac5f864d31a2797c6108e5b2459d69c023f34be1e2ec58fcb958c9e51a55458d27775076909
7
- data.tar.gz: 763264ae25e2c483f541cd8143d9a177c3ff5392fdc217c5b495c06e64242e9f7805266696670af94ff263cb321cc81f3659fb55240d5ae013528721f9aeefaf
6
+ metadata.gz: d3ad4f0e61e6b00294a12e80a8d389b58c7230797fe3617585fdf4d39c9dd0da2481d1fb1da476543a3e14c5bb42891d70cadd98f540a0c1ec859237581fcc9b
7
+ data.tar.gz: e980bb1e8a8fd53bd844ad8b8d41c20be01eb3ada85322748c29e1cf68e24f99e137d1719b69f047dcea53646f85ce96f9bfb16fa0237ddc5d494c5dd4ecb4b8
@@ -1,3 +1,11 @@
1
+ ## 3.0.0 (2015-10-26)
2
+
3
+ Changes:
4
+
5
+ - Remove query string from redirect_uri on callback by default (#221, @gioblu)
6
+ - Signed request parsing extracted to `OmniAuth::Facebook::SignedRequest` class. (#183, @simi, @Vrael)
7
+ - Change default value of `info_fields` to `name,email` for the [graph-api-v2.4](https://developers.facebook.com/blog/post/2015/07/08/graph-api-v2.4/). ([#209](https://github.com/mkdynamic/omniauth-facebook/pull/209))
8
+
1
9
  ## 2.0.1 (2015-02-21)
2
10
 
3
11
  Bugfixes:
data/README.md CHANGED
@@ -3,7 +3,8 @@ More details [here](https://github.com/mkdynamic/omniauth-facebook/wiki/CSRF-vul
3
3
 
4
4
  ---
5
5
 
6
- # OmniAuth Facebook  [![Build Status](https://secure.travis-ci.org/mkdynamic/omniauth-facebook.png?branch=master)](https://travis-ci.org/mkdynamic/omniauth-facebook)
6
+ # OmniAuth Facebook  [![Build Status](https://secure.travis-ci.org/mkdynamic/omniauth-facebook.svg?branch=master)](https://travis-ci.org/mkdynamic/omniauth-facebook) [![Gem Version](https://img.shields.io/gem/v/omniauth-facebook.svg)](https://rubygems.org/gems/omniauth-facebook)
7
+
7
8
 
8
9
  **These notes are based on master, please see tags for README pertaining to specific releases.**
9
10
 
@@ -44,9 +45,9 @@ Option name | Default | Explanation
44
45
  `scope` | `email` | A comma-separated list of permissions you want to request from the user. See the Facebook docs for a full list of available permissions: https://developers.facebook.com/docs/reference/login/
45
46
  `display` | `page` | The display context to show the authentication page. Options are: `page`, `popup` and `touch`. Read the Facebook docs for more details: https://developers.facebook.com/docs/reference/dialogs/oauth/
46
47
  `image_size` | `square` | 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.
47
- `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/graph-api/reference/user/ (only `/me` endpoint).
48
+ `info_fields` | 'name,email' | 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/graph-api/reference/user/ (only `/me` endpoint).
48
49
  `locale` | | Specify locale which should be used when getting the user's info. Value should be locale string as per https://developers.facebook.com/docs/reference/api/locale/.
49
- `auth_type` | | Optionally specifies the requested authentication features as a comma-separated list, as per https://developers.facebook.com/docs/facebook-login/reauthentication/. 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`.
50
+ `auth_type` | | Optionally specifies the requested authentication features as a comma-separated list, as per https://developers.facebook.com/docs/facebook-login/reauthentication/. 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). Use 'rerequest' when you want to request premissions. Default is `nil`.
50
51
  `secure_image_url` | `false` | Set to `true` to use https for the avatar image url returned in the auth hash.
51
52
  `callback_url` / `callback_path` | | Specify a custom callback URL used during the server-side flow. Note this must be allowed by your app configuration on Facebook (see 'Valid OAuth redirect URIs' under the 'Advanced' settings section in the configuration for your Facebook app for more details).
52
53
 
@@ -178,4 +179,3 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
178
179
 
179
180
 
180
181
  [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/mkdynamic/omniauth-facebook/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
181
-
data/Rakefile CHANGED
@@ -3,6 +3,7 @@ require 'rake/testtask'
3
3
 
4
4
  Rake::TestTask.new do |task|
5
5
  task.libs << 'test'
6
+ task.test_files = FileList['test/*_test.rb']
6
7
  end
7
8
 
8
9
  task :default => :test
@@ -0,0 +1,52 @@
1
+ require 'openssl'
2
+
3
+ module OmniAuth
4
+ module Facebook
5
+ class SignedRequest
6
+ class UnknownSignatureAlgorithmError < NotImplementedError; end
7
+ SUPPORTED_ALGORITHM = 'HMAC-SHA256'
8
+
9
+ attr_reader :value, :secret
10
+
11
+ def self.parse(value, secret)
12
+ new(value, secret).payload
13
+ end
14
+
15
+ def initialize(value, secret)
16
+ @value = value
17
+ @secret = secret
18
+ end
19
+
20
+ def payload
21
+ @payload ||= parse_signed_request
22
+ end
23
+
24
+ private
25
+
26
+ def parse_signed_request
27
+ signature, encoded_payload = value.split('.')
28
+ return if signature.nil?
29
+
30
+ decoded_hex_signature = base64_decode_url(signature)
31
+ decoded_payload = MultiJson.decode(base64_decode_url(encoded_payload))
32
+
33
+ unless decoded_payload['algorithm'] == SUPPORTED_ALGORITHM
34
+ raise UnknownSignatureAlgorithmError, "unknown algorithm: #{decoded_payload['algorithm']}"
35
+ end
36
+
37
+ if valid_signature?(decoded_hex_signature, encoded_payload)
38
+ decoded_payload
39
+ end
40
+ end
41
+
42
+ def valid_signature?(signature, payload, algorithm = OpenSSL::Digest::SHA256.new)
43
+ OpenSSL::HMAC.digest(algorithm, secret, payload) == signature
44
+ end
45
+
46
+ def base64_decode_url(value)
47
+ value += '=' * (4 - value.size.modulo(4))
48
+ Base64.decode64(value.tr('-_', '+/'))
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module Facebook
3
- VERSION = "2.0.1"
3
+ VERSION = "3.0.0"
4
4
  end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  require 'omniauth/strategies/oauth2'
2
- require 'base64'
2
+ require 'omniauth/facebook/signed_request'
3
3
  require 'openssl'
4
4
  require 'rack/utils'
5
5
  require 'uri'
@@ -8,10 +8,8 @@ module OmniAuth
8
8
  module Strategies
9
9
  class Facebook < OmniAuth::Strategies::OAuth2
10
10
  class NoAuthorizationCodeError < StandardError; end
11
- class UnknownSignatureAlgorithmError < NotImplementedError; end
12
11
 
13
12
  DEFAULT_SCOPE = 'email'
14
- SUPPORTED_ALGORITHM = 'HMAC-SHA256'
15
13
 
16
14
  option :client_options, {
17
15
  :site => 'https://graph.facebook.com',
@@ -62,7 +60,7 @@ module OmniAuth
62
60
 
63
61
  def info_options
64
62
  params = {:appsecret_proof => appsecret_proof}
65
- params.merge!({:fields => options[:info_fields]}) if options[:info_fields]
63
+ params.merge!({:fields => (options[:info_fields] || 'name,email')})
66
64
  params.merge!({:locale => options[:locale]}) if options[:locale]
67
65
 
68
66
  { :params => params }
@@ -74,7 +72,7 @@ module OmniAuth
74
72
  end
75
73
  rescue NoAuthorizationCodeError => e
76
74
  fail!(:no_authorization_code, e)
77
- rescue UnknownSignatureAlgorithmError => e
75
+ rescue OmniAuth::Facebook::SignedRequest::UnknownSignatureAlgorithmError => e
78
76
  fail!(:unknown_signature_algorithm, e)
79
77
  end
80
78
 
@@ -85,7 +83,8 @@ module OmniAuth
85
83
  if @authorization_code_from_signed_request_in_cookie
86
84
  ''
87
85
  else
88
- options[:callback_url] || super
86
+ # Fixes regression in omniauth-oauth2 v1.4.0 by https://github.com/intridea/omniauth-oauth2/commit/85fdbe117c2a4400d001a6368cc359d88f40abc7
87
+ options[:callback_url] || (full_host + script_name + callback_path)
89
88
  end
90
89
  end
91
90
 
@@ -120,7 +119,7 @@ module OmniAuth
120
119
  private
121
120
 
122
121
  def signed_request_from_cookie
123
- @signed_request_from_cookie ||= raw_signed_request_from_cookie && parse_signed_request(raw_signed_request_from_cookie)
122
+ @signed_request_from_cookie ||= raw_signed_request_from_cookie && OmniAuth::Facebook::SignedRequest.parse(raw_signed_request_from_cookie, client.secret)
124
123
  end
125
124
 
126
125
  def raw_signed_request_from_cookie
@@ -160,31 +159,6 @@ module OmniAuth
160
159
  end
161
160
  end
162
161
 
163
- def parse_signed_request(value)
164
- signature, encoded_payload = value.split('.')
165
- return if signature.nil?
166
-
167
- decoded_hex_signature = base64_decode_url(signature)
168
- decoded_payload = MultiJson.decode(base64_decode_url(encoded_payload))
169
-
170
- unless decoded_payload['algorithm'] == SUPPORTED_ALGORITHM
171
- raise UnknownSignatureAlgorithmError, "unknown algorithm: #{decoded_payload['algorithm']}"
172
- end
173
-
174
- if valid_signature?(client.secret, decoded_hex_signature, encoded_payload)
175
- decoded_payload
176
- end
177
- end
178
-
179
- def valid_signature?(secret, signature, payload, algorithm = OpenSSL::Digest::SHA256.new)
180
- OpenSSL::HMAC.digest(algorithm, secret, payload) == signature
181
- end
182
-
183
- def base64_decode_url(value)
184
- value += '=' * (4 - value.size.modulo(4))
185
- Base64.decode64(value.tr('-_', '+/'))
186
- end
187
-
188
162
  def image_url(uid, options)
189
163
  uri_class = options[:secure_image_url] ? URI::HTTPS : URI::HTTP
190
164
  site_uri = URI.parse(client.site)
@@ -0,0 +1,16 @@
1
+ {
2
+ "algorithm": "HMAC-SHA256",
3
+ "expires": 1308988800,
4
+ "issued_at": 1308985018,
5
+ "oauth_token": "111111111111111|2.AQBAttRlLVnwqNPZ.3600.1111111111.1-111111111111111|T49w3BqoZUegypru51Gra70hED8",
6
+ "user":
7
+ {
8
+ "country": "de",
9
+ "locale": "en_US",
10
+ "age":
11
+ {
12
+ "min": 21
13
+ }
14
+ },
15
+ "user_id": "111111111111111"
16
+ }
@@ -0,0 +1 @@
1
+ 53umfudisP7mKhsi9nZboBg15yMZKhfQAARL9UoZtSE.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImV4cGlyZXMiOjEzMDg5ODg4MDAsImlzc3VlZF9hdCI6MTMwODk4NTAxOCwib2F1dGhfdG9rZW4iOiIxMTExMTExMTExMTExMTF8Mi5BUUJBdHRSbExWbndxTlBaLjM2MDAuMTExMTExMTExMS4xLTExMTExMTExMTExMTExMXxUNDl3M0Jxb1pVZWd5cHJ1NTFHcmE3MGhFRDgiLCJ1c2VyIjp7ImNvdW50cnkiOiJkZSIsImxvY2FsZSI6ImVuX1VTIiwiYWdlIjp7Im1pbiI6MjF9fSwidXNlcl9pZCI6IjExMTExMTExMTExMTExMSJ9
@@ -0,0 +1,26 @@
1
+ require 'helper'
2
+ require 'omniauth/facebook/signed_request'
3
+
4
+ class SignedRequestTest < Minitest::Test
5
+ def setup
6
+ @value = fixture('signed_request.txt').strip
7
+ @secret = "897z956a2z7zzzzz5783z458zz3z7556"
8
+ @expected_payload = MultiJson.decode(fixture('payload.json'))
9
+ end
10
+
11
+ def test_signed_request_payload
12
+ signed_request = OmniAuth::Facebook::SignedRequest.new(@value, @secret)
13
+ assert_equal @expected_payload, signed_request.payload
14
+ end
15
+
16
+ def test_signed_request_parse
17
+ payload = OmniAuth::Facebook::SignedRequest.parse(@value, @secret)
18
+ assert_equal @expected_payload, payload
19
+ end
20
+
21
+ private
22
+
23
+ def fixture(name)
24
+ File.read(File.expand_path("fixtures/#{name}", File.dirname(__FILE__)))
25
+ end
26
+ end
@@ -24,18 +24,20 @@ class ClientTest < StrategyTestCase
24
24
  end
25
25
 
26
26
  class CallbackUrlTest < StrategyTestCase
27
- test "returns the default callback url" do
27
+ test "returns the default callback url (omitting querystring)" do
28
28
  url_base = 'http://auth.request.com'
29
29
  @request.stubs(:url).returns("#{url_base}/some/page")
30
30
  strategy.stubs(:script_name).returns('') # as not to depend on Rack env
31
+ strategy.stubs(:query_string).returns('?foo=bar')
31
32
  assert_equal "#{url_base}/auth/facebook/callback", strategy.callback_url
32
33
  end
33
34
 
34
- test "returns path from callback_path option" do
35
+ test "returns path from callback_path option (omitting querystring)" do
35
36
  @options = { :callback_path => "/auth/FB/done"}
36
37
  url_base = 'http://auth.request.com'
37
38
  @request.stubs(:url).returns("#{url_base}/page/path")
38
39
  strategy.stubs(:script_name).returns('') # as not to depend on Rack env
40
+ strategy.stubs(:query_string).returns('?foo=bar')
39
41
  assert_equal "#{url_base}/auth/FB/done", strategy.callback_url
40
42
  end
41
43
 
@@ -259,7 +261,7 @@ class RawInfoTest < StrategyTestCase
259
261
  super
260
262
  @access_token = stub('OAuth2::AccessToken')
261
263
  @appsecret_proof = 'appsecret_proof'
262
- @options = {:appsecret_proof => @appsecret_proof}
264
+ @options = {:appsecret_proof => @appsecret_proof, :fields => 'name,email'}
263
265
  end
264
266
 
265
267
  test 'performs a GET to https://graph.facebook.com/me' do
@@ -288,6 +290,14 @@ class RawInfoTest < StrategyTestCase
288
290
  strategy.raw_info
289
291
  end
290
292
 
293
+ test 'performs a GET to https://graph.facebook.com/me with default info_fields' do
294
+ strategy.stubs(:access_token).returns(@access_token)
295
+ strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
296
+ params = {:params => {:appsecret_proof => @appsecret_proof, :fields => 'name,email'}}
297
+ @access_token.expects(:get).with('me', params).returns(stub_everything('OAuth2::Response'))
298
+ strategy.raw_info
299
+ end
300
+
291
301
  test 'returns a Hash' do
292
302
  strategy.stubs(:access_token).returns(@access_token)
293
303
  strategy.stubs(:appsecret_proof).returns(@appsecret_proof)
@@ -437,7 +447,7 @@ module SignedRequestTests
437
447
 
438
448
  test 'throws an error if the algorithm is unknown' do
439
449
  setup('UNKNOWN-ALGO')
440
- assert_equal "unknown algorithm: UNKNOWN-ALGO", assert_raises(OmniAuth::Strategies::Facebook::UnknownSignatureAlgorithmError) { strategy.send(:signed_request_from_cookie) }.message
450
+ assert_equal "unknown algorithm: UNKNOWN-ALGO", assert_raises(OmniAuth::Facebook::SignedRequest::UnknownSignatureAlgorithmError) { strategy.send(:signed_request_from_cookie) }.message
441
451
  end
442
452
  end
443
453
 
@@ -497,7 +507,7 @@ module SignedRequestTests
497
507
  end
498
508
 
499
509
  test 'calls fail! when an algorithm is unknown' do
500
- strategy.expects(:fail!).times(1).with(:unknown_signature_algorithm, kind_of(OmniAuth::Strategies::Facebook::UnknownSignatureAlgorithmError))
510
+ strategy.expects(:fail!).times(1).with(:unknown_signature_algorithm, kind_of(OmniAuth::Facebook::SignedRequest::UnknownSignatureAlgorithmError))
501
511
  strategy.callback_phase
502
512
  end
503
513
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-facebook
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Dodwell
@@ -9,62 +9,62 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-21 00:00:00.000000000 Z
12
+ date: 2015-10-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: omniauth-oauth2
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ~>
19
19
  - !ruby/object:Gem::Version
20
20
  version: '1.2'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ~>
26
26
  - !ruby/object:Gem::Version
27
27
  version: '1.2'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: minitest
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ">="
32
+ - - '>='
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ">="
39
+ - - '>='
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: mocha
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ">="
46
+ - - '>='
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ">="
53
+ - - '>='
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rake
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ">="
60
+ - - '>='
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ">="
67
+ - - '>='
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  description:
@@ -75,8 +75,8 @@ executables: []
75
75
  extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
78
- - ".gitignore"
79
- - ".travis.yml"
78
+ - .gitignore
79
+ - .travis.yml
80
80
  - CHANGELOG.md
81
81
  - Gemfile
82
82
  - README.md
@@ -87,12 +87,16 @@ files:
87
87
  - example/config.ru
88
88
  - lib/omniauth-facebook.rb
89
89
  - lib/omniauth/facebook.rb
90
+ - lib/omniauth/facebook/signed_request.rb
90
91
  - lib/omniauth/facebook/version.rb
91
92
  - lib/omniauth/strategies/facebook.rb
92
93
  - omniauth-facebook.gemspec
94
+ - test/fixtures/payload.json
95
+ - test/fixtures/signed_request.txt
93
96
  - test/helper.rb
97
+ - test/signed_request_test.rb
98
+ - test/strategy_test.rb
94
99
  - test/support/shared_examples.rb
95
- - test/test.rb
96
100
  homepage: https://github.com/mkdynamic/omniauth-facebook
97
101
  licenses:
98
102
  - MIT
@@ -103,21 +107,24 @@ require_paths:
103
107
  - lib
104
108
  required_ruby_version: !ruby/object:Gem::Requirement
105
109
  requirements:
106
- - - ">="
110
+ - - '>='
107
111
  - !ruby/object:Gem::Version
108
112
  version: '0'
109
113
  required_rubygems_version: !ruby/object:Gem::Requirement
110
114
  requirements:
111
- - - ">="
115
+ - - '>='
112
116
  - !ruby/object:Gem::Version
113
117
  version: '0'
114
118
  requirements: []
115
119
  rubyforge_project:
116
- rubygems_version: 2.4.5
120
+ rubygems_version: 2.0.14
117
121
  signing_key:
118
122
  specification_version: 4
119
123
  summary: Facebook OAuth2 Strategy for OmniAuth
120
124
  test_files:
125
+ - test/fixtures/payload.json
126
+ - test/fixtures/signed_request.txt
121
127
  - test/helper.rb
128
+ - test/signed_request_test.rb
129
+ - test/strategy_test.rb
122
130
  - test/support/shared_examples.rb
123
- - test/test.rb