omniauth-facebook2 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/omniauth/facebook2/signed_request.rb +10 -10
- data/lib/omniauth/facebook2/version.rb +1 -1
- data/lib/omniauth/facebook2.rb +3 -3
- data/lib/omniauth/strategies/facebook2.rb +60 -60
- data/lib/omniauth-facebook2.rb +1 -1
- data/omniauth-facebook2.gemspec +22 -22
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c2fed6fe78aaec447b3ef10186c6b09e5af585c7362887b1ab2a690e6a494d92
|
|
4
|
+
data.tar.gz: b9419b8295724e0ed582c78c2b5275b4aa40897ff0e81ef04a046b495da89f89
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 15478c0698d021ac155fca06623a826999362b3a161bcd839ec65bbd731887e477767c8504a107ce87c8bca38bf8dba6f004c07d47106a1a3050d528db97d4c3
|
|
7
|
+
data.tar.gz: 671e5abb1f82d17f267fa972eb01e2cd5cbfb194651f5aac4c98f0306bc10c3af6329bc97388df45ab2708a2ede7897d03d1f58c8318d30de63d2af4bf57698f
|
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# OmniAuth
|
|
1
|
+
# OmniAuth Facebook Strategy
|
|
2
2
|
|
|
3
3
|
[](https://github.com/icoretech/omniauth-facebook2/actions/workflows/test.yml?query=branch%3Amain)
|
|
4
4
|
[](https://badge.fury.io/rb/omniauth-facebook2)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
3
|
+
require "base64"
|
|
4
|
+
require "json"
|
|
5
|
+
require "openssl"
|
|
6
6
|
|
|
7
7
|
module OmniAuth
|
|
8
8
|
module Facebook2
|
|
@@ -10,7 +10,7 @@ module OmniAuth
|
|
|
10
10
|
class SignedRequest
|
|
11
11
|
class UnknownSignatureAlgorithmError < NotImplementedError; end
|
|
12
12
|
|
|
13
|
-
SUPPORTED_ALGORITHM =
|
|
13
|
+
SUPPORTED_ALGORITHM = "HMAC-SHA256"
|
|
14
14
|
|
|
15
15
|
attr_reader :value, :secret
|
|
16
16
|
|
|
@@ -30,26 +30,26 @@ module OmniAuth
|
|
|
30
30
|
private
|
|
31
31
|
|
|
32
32
|
def parse_signed_request
|
|
33
|
-
signature, encoded_payload = value.to_s.split(
|
|
33
|
+
signature, encoded_payload = value.to_s.split(".", 2)
|
|
34
34
|
return if blank?(signature) || blank?(encoded_payload)
|
|
35
35
|
|
|
36
36
|
decoded_signature = base64_decode_url(signature)
|
|
37
37
|
decoded_payload = JSON.parse(base64_decode_url(encoded_payload))
|
|
38
38
|
|
|
39
|
-
unless decoded_payload[
|
|
40
|
-
raise UnknownSignatureAlgorithmError, "unknown algorithm: #{decoded_payload[
|
|
39
|
+
unless decoded_payload["algorithm"] == SUPPORTED_ALGORITHM
|
|
40
|
+
raise UnknownSignatureAlgorithmError, "unknown algorithm: #{decoded_payload["algorithm"]}"
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
decoded_payload if valid_signature?(decoded_signature, encoded_payload)
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
def valid_signature?(signature, payload, algorithm = OpenSSL::Digest.new(
|
|
46
|
+
def valid_signature?(signature, payload, algorithm = OpenSSL::Digest.new("SHA256"))
|
|
47
47
|
OpenSSL::HMAC.digest(algorithm, secret, payload) == signature
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
def base64_decode_url(value)
|
|
51
|
-
value +=
|
|
52
|
-
Base64.decode64(value.tr(
|
|
51
|
+
value += "=" * ((4 - value.size.modulo(4)) % 4)
|
|
52
|
+
Base64.decode64(value.tr("-_", "+/"))
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
def blank?(value)
|
data/lib/omniauth/facebook2.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
3
|
+
require "omniauth/facebook2/version"
|
|
4
|
+
require "omniauth/facebook2/signed_request"
|
|
5
|
+
require "omniauth/strategies/facebook2"
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
3
|
+
require "omniauth-oauth2"
|
|
4
|
+
require "openssl"
|
|
5
|
+
require "rack/utils"
|
|
6
|
+
require "uri"
|
|
7
7
|
|
|
8
8
|
module OmniAuth
|
|
9
9
|
module Strategies
|
|
@@ -11,12 +11,12 @@ module OmniAuth
|
|
|
11
11
|
class Facebook2 < OmniAuth::Strategies::OAuth2
|
|
12
12
|
class NoAuthorizationCodeError < StandardError; end
|
|
13
13
|
|
|
14
|
-
DEFAULT_SCOPE =
|
|
15
|
-
DEFAULT_FACEBOOK_API_VERSION =
|
|
16
|
-
DEFAULT_INFO_FIELDS =
|
|
17
|
-
DEFAULT_TOKEN_URL =
|
|
14
|
+
DEFAULT_SCOPE = "email"
|
|
15
|
+
DEFAULT_FACEBOOK_API_VERSION = "v25.0"
|
|
16
|
+
DEFAULT_INFO_FIELDS = "name,email"
|
|
17
|
+
DEFAULT_TOKEN_URL = "oauth/access_token"
|
|
18
18
|
|
|
19
|
-
option :name,
|
|
19
|
+
option :name, "facebook2"
|
|
20
20
|
option :scope, DEFAULT_SCOPE
|
|
21
21
|
option :api_version, DEFAULT_FACEBOOK_API_VERSION
|
|
22
22
|
option :authorize_options, %i[scope display auth_type config_id redirect_uri]
|
|
@@ -25,61 +25,61 @@ module OmniAuth
|
|
|
25
25
|
option :authorization_code_from_signed_request_in_cookie, nil
|
|
26
26
|
|
|
27
27
|
option :client_options,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
site: "https://graph.facebook.com/#{DEFAULT_FACEBOOK_API_VERSION}",
|
|
29
|
+
authorize_url: "https://www.facebook.com/#{DEFAULT_FACEBOOK_API_VERSION}/dialog/oauth",
|
|
30
|
+
token_url: DEFAULT_TOKEN_URL,
|
|
31
|
+
connection_opts: {
|
|
32
|
+
headers: {
|
|
33
|
+
user_agent: "icoretech-omniauth-facebook2 gem",
|
|
34
|
+
accept: "application/json",
|
|
35
|
+
content_type: "application/json"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
38
|
|
|
39
39
|
option :access_token_options,
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
header_format: "OAuth %s",
|
|
41
|
+
param_name: "access_token"
|
|
42
42
|
|
|
43
|
-
uid { raw_info[
|
|
43
|
+
uid { raw_info["id"] }
|
|
44
44
|
|
|
45
45
|
info do
|
|
46
46
|
prune(
|
|
47
47
|
{
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
48
|
+
"nickname" => raw_info["username"],
|
|
49
|
+
"email" => raw_info["email"],
|
|
50
|
+
"name" => raw_info["name"],
|
|
51
|
+
"first_name" => raw_info["first_name"],
|
|
52
|
+
"last_name" => raw_info["last_name"],
|
|
53
|
+
"image" => image_url(uid),
|
|
54
|
+
"description" => raw_info["bio"],
|
|
55
|
+
"urls" => {
|
|
56
|
+
"Facebook" => raw_info["link"],
|
|
57
|
+
"Website" => raw_info["website"]
|
|
58
58
|
},
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
"location" => raw_info.dig("location", "name"),
|
|
60
|
+
"verified" => raw_info["verified"]
|
|
61
61
|
}
|
|
62
62
|
)
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
credentials do
|
|
66
66
|
{
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
"token" => access_token.token,
|
|
68
|
+
"refresh_token" => access_token.refresh_token,
|
|
69
|
+
"expires_at" => access_token.expires_at,
|
|
70
|
+
"expires" => access_token.expires?,
|
|
71
|
+
"scope" => token_scope
|
|
72
72
|
}.compact
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
extra do
|
|
76
76
|
data = {}
|
|
77
|
-
data[
|
|
77
|
+
data["raw_info"] = raw_info unless skip_info?
|
|
78
78
|
prune(data)
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
def raw_info
|
|
82
|
-
@raw_info ||= access_token.get(
|
|
82
|
+
@raw_info ||= access_token.get("me", info_options).parsed || {}
|
|
83
83
|
end
|
|
84
84
|
|
|
85
85
|
def info_options
|
|
@@ -89,7 +89,7 @@ module OmniAuth
|
|
|
89
89
|
params[:appsecret_proof] = appsecret_proof if options[:appsecret_proof]
|
|
90
90
|
params[:locale] = options[:locale] if options[:locale]
|
|
91
91
|
|
|
92
|
-
{
|
|
92
|
+
{params: params}
|
|
93
93
|
end
|
|
94
94
|
|
|
95
95
|
def callback_phase
|
|
@@ -115,13 +115,13 @@ module OmniAuth
|
|
|
115
115
|
end
|
|
116
116
|
|
|
117
117
|
def callback_url
|
|
118
|
-
return
|
|
118
|
+
return "" if options.authorization_code_from_signed_request_in_cookie
|
|
119
119
|
|
|
120
120
|
options[:callback_url] || super
|
|
121
121
|
end
|
|
122
122
|
|
|
123
123
|
def query_string
|
|
124
|
-
return
|
|
124
|
+
return "" if request.params["code"]
|
|
125
125
|
|
|
126
126
|
super
|
|
127
127
|
end
|
|
@@ -163,10 +163,10 @@ module OmniAuth
|
|
|
163
163
|
end
|
|
164
164
|
|
|
165
165
|
def with_authorization_code!
|
|
166
|
-
if request.params.key?(
|
|
166
|
+
if request.params.key?("code") && !blank?(request.params["code"])
|
|
167
167
|
yield
|
|
168
|
-
elsif (code_from_signed_request = signed_request_from_cookie && signed_request_from_cookie[
|
|
169
|
-
request.params[
|
|
168
|
+
elsif (code_from_signed_request = signed_request_from_cookie && signed_request_from_cookie["code"])
|
|
169
|
+
request.params["code"] = code_from_signed_request
|
|
170
170
|
options.authorization_code_from_signed_request_in_cookie = true
|
|
171
171
|
original_provider_ignores_state = options.provider_ignores_state
|
|
172
172
|
options.provider_ignores_state = true
|
|
@@ -174,13 +174,13 @@ module OmniAuth
|
|
|
174
174
|
begin
|
|
175
175
|
yield
|
|
176
176
|
ensure
|
|
177
|
-
request.params.delete(
|
|
177
|
+
request.params.delete("code")
|
|
178
178
|
options.authorization_code_from_signed_request_in_cookie = false
|
|
179
179
|
options.provider_ignores_state = original_provider_ignores_state
|
|
180
180
|
end
|
|
181
181
|
else
|
|
182
182
|
raise NoAuthorizationCodeError,
|
|
183
|
-
|
|
183
|
+
"must pass either a `code` (query param) or an `fbsr_<app_id>` signed request cookie"
|
|
184
184
|
end
|
|
185
185
|
end
|
|
186
186
|
|
|
@@ -199,26 +199,26 @@ module OmniAuth
|
|
|
199
199
|
url = uri_class.build(host: site_uri.host, path: "#{site_uri.path}/#{user_id}/picture")
|
|
200
200
|
|
|
201
201
|
query = if options[:image_size].is_a?(String) || options[:image_size].is_a?(Symbol)
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
202
|
+
{type: options[:image_size]}
|
|
203
|
+
elsif options[:image_size].is_a?(Hash)
|
|
204
|
+
options[:image_size]
|
|
205
|
+
end
|
|
206
206
|
url.query = Rack::Utils.build_query(query) if query
|
|
207
207
|
|
|
208
208
|
url.to_s
|
|
209
209
|
end
|
|
210
210
|
|
|
211
211
|
def appsecret_proof
|
|
212
|
-
@appsecret_proof ||= OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new(
|
|
212
|
+
@appsecret_proof ||= OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("SHA256"), client.secret, access_token.token)
|
|
213
213
|
end
|
|
214
214
|
|
|
215
215
|
def token_scope
|
|
216
216
|
token_params = access_token.respond_to?(:params) ? access_token.params : {}
|
|
217
|
-
token_params[
|
|
217
|
+
token_params["scope"] || (access_token["scope"] if access_token.respond_to?(:[]))
|
|
218
218
|
end
|
|
219
219
|
|
|
220
220
|
def missing_session_state?
|
|
221
|
-
present?(request.params[
|
|
221
|
+
present?(request.params["state"]) && blank?(session["omniauth.state"])
|
|
222
222
|
end
|
|
223
223
|
|
|
224
224
|
def oauth_state_nil_compare_error?(error)
|
|
@@ -228,7 +228,7 @@ module OmniAuth
|
|
|
228
228
|
def fail_state_mismatch
|
|
229
229
|
fail!(
|
|
230
230
|
:csrf_detected,
|
|
231
|
-
OmniAuth::Strategies::OAuth2::CallbackError.new(:csrf_detected,
|
|
231
|
+
OmniAuth::Strategies::OAuth2::CallbackError.new(:csrf_detected, "OAuth state was missing or mismatched")
|
|
232
232
|
)
|
|
233
233
|
end
|
|
234
234
|
|
|
@@ -275,10 +275,10 @@ module OmniAuth
|
|
|
275
275
|
|
|
276
276
|
# Backward-compatible strategy name for existing `facebook` callback paths.
|
|
277
277
|
class Facebook < Facebook2
|
|
278
|
-
option :name,
|
|
278
|
+
option :name, "facebook"
|
|
279
279
|
end
|
|
280
280
|
end
|
|
281
281
|
end
|
|
282
282
|
|
|
283
|
-
OmniAuth.config.add_camelization
|
|
284
|
-
OmniAuth.config.add_camelization
|
|
283
|
+
OmniAuth.config.add_camelization "facebook2", "Facebook2"
|
|
284
|
+
OmniAuth.config.add_camelization "facebook", "Facebook"
|
data/lib/omniauth-facebook2.rb
CHANGED
data/omniauth-facebook2.gemspec
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
lib = File.expand_path(
|
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
-
require
|
|
5
|
+
require "omniauth/facebook2/version"
|
|
6
6
|
|
|
7
7
|
Gem::Specification.new do |spec|
|
|
8
|
-
spec.name =
|
|
8
|
+
spec.name = "omniauth-facebook2"
|
|
9
9
|
spec.version = OmniAuth::Facebook2::VERSION
|
|
10
|
-
spec.authors = [
|
|
11
|
-
spec.email = [
|
|
10
|
+
spec.authors = ["Claudio Poli"]
|
|
11
|
+
spec.email = ["masterkain@gmail.com"]
|
|
12
12
|
|
|
13
|
-
spec.summary =
|
|
13
|
+
spec.summary = "OmniAuth strategy for Facebook OAuth2 authentication."
|
|
14
14
|
spec.description =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
spec.homepage =
|
|
18
|
-
spec.license =
|
|
19
|
-
spec.required_ruby_version =
|
|
15
|
+
"OAuth2 strategy for OmniAuth that authenticates users with Facebook " \
|
|
16
|
+
"and exposes profile metadata from the Graph API."
|
|
17
|
+
spec.homepage = "https://github.com/icoretech/omniauth-facebook2"
|
|
18
|
+
spec.license = "MIT"
|
|
19
|
+
spec.required_ruby_version = ">= 3.2"
|
|
20
20
|
|
|
21
|
-
spec.metadata[
|
|
22
|
-
spec.metadata[
|
|
23
|
-
spec.metadata[
|
|
24
|
-
spec.metadata[
|
|
21
|
+
spec.metadata["source_code_uri"] = "https://github.com/icoretech/omniauth-facebook2"
|
|
22
|
+
spec.metadata["bug_tracker_uri"] = "https://github.com/icoretech/omniauth-facebook2/issues"
|
|
23
|
+
spec.metadata["changelog_uri"] = "https://github.com/icoretech/omniauth-facebook2/releases"
|
|
24
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
|
25
25
|
|
|
26
26
|
spec.files = Dir[
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
"lib/**/*.rb",
|
|
28
|
+
"README*",
|
|
29
|
+
"LICENSE*",
|
|
30
|
+
"*.gemspec"
|
|
31
31
|
]
|
|
32
|
-
spec.require_paths = [
|
|
32
|
+
spec.require_paths = ["lib"]
|
|
33
33
|
|
|
34
|
-
spec.add_dependency
|
|
35
|
-
spec.add_dependency
|
|
34
|
+
spec.add_dependency "cgi", ">= 0.3.6"
|
|
35
|
+
spec.add_dependency "omniauth-oauth2", ">= 1.8", "< 2.0"
|
|
36
36
|
end
|