sorcery 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sorcery might be problematic. Click here for more details.
- data/Gemfile +4 -4
- data/Gemfile.lock +5 -22
- data/README.rdoc +2 -2
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/generators/sorcery/templates/initializer.rb +24 -13
- data/lib/generators/sorcery/templates/migration/activity_logging.rb +2 -0
- data/lib/sorcery/controller/submodules/activity_logging.rb +12 -1
- data/lib/sorcery/controller/submodules/external/protocols/oauth1.rb +14 -3
- data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +5 -1
- data/lib/sorcery/controller/submodules/external/providers/base.rb +21 -0
- data/lib/sorcery/controller/submodules/external/providers/facebook.rb +13 -12
- data/lib/sorcery/controller/submodules/external/providers/github.rb +4 -3
- data/lib/sorcery/controller/submodules/external/providers/google.rb +4 -3
- data/lib/sorcery/controller/submodules/external/providers/linkedin.rb +13 -12
- data/lib/sorcery/controller/submodules/external/providers/liveid.rb +5 -4
- data/lib/sorcery/controller/submodules/external/providers/twitter.rb +15 -14
- data/lib/sorcery/controller/submodules/external/providers/vk.rb +6 -5
- data/lib/sorcery/controller/submodules/external/providers/xing.rb +97 -0
- data/lib/sorcery/controller/submodules/external.rb +72 -39
- data/lib/sorcery/controller.rb +5 -2
- data/lib/sorcery/model/submodules/activity_logging.rb +3 -0
- data/lib/sorcery/model/submodules/brute_force_protection.rb +14 -12
- data/lib/sorcery/model.rb +1 -1
- data/lib/sorcery/railties/tasks.rake +1 -7
- data/lib/sorcery.rb +3 -1
- data/sorcery.gemspec +11 -12
- data/spec/Gemfile +1 -1
- data/spec/Gemfile.lock +1 -1
- data/spec/rails3/Gemfile.lock +3 -3
- data/spec/rails3/app/models/user.rb +1 -1
- data/spec/rails3/app/views/sorcery_mailer/send_unlock_token_email.text.erb +1 -1
- data/spec/rails3/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +2 -0
- data/spec/rails3/spec/controller_activity_logging_spec.rb +15 -0
- data/spec/rails3/spec/controller_brute_force_protection_spec.rb +14 -6
- data/spec/rails3/spec/controller_spec.rb +32 -27
- data/spec/rails3_mongo_mapper/Gemfile.lock +3 -3
- data/spec/rails3_mongo_mapper/spec/controller_spec.rb +32 -27
- data/spec/rails3_mongoid/Gemfile.lock +3 -3
- data/spec/rails3_mongoid/spec/controller_activity_logging_spec.rb +6 -0
- data/spec/rails3_mongoid/spec/controller_spec.rb +33 -28
- data/spec/shared_examples/user_activity_logging_shared_examples.rb +5 -0
- metadata +138 -59
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
# Add dependencies required to use your gem here.
|
3
3
|
# Example:
|
4
4
|
# gem "activesupport", ">= 2.3.5"
|
@@ -11,11 +11,11 @@ gem 'bcrypt-ruby', "~> 3.0.0"
|
|
11
11
|
group :development do
|
12
12
|
gem 'abstract', '>= 1.0.0'
|
13
13
|
gem "rails", ">= 3.0.0"
|
14
|
-
gem 'json', ">= 1.
|
14
|
+
gem 'json', ">= 1.7.7"
|
15
15
|
gem "rspec", "~> 2.5.0"
|
16
16
|
gem 'rspec-rails', "~> 2.5.0"
|
17
|
-
gem 'ruby-debug19'
|
18
|
-
gem 'sqlite3
|
17
|
+
#gem 'ruby-debug19'
|
18
|
+
gem 'sqlite3'
|
19
19
|
gem "yard", "~> 0.6.0"
|
20
20
|
gem "bundler", ">= 1.1.0"
|
21
21
|
gem "jeweler", "~> 1.8.3"
|
data/Gemfile.lock
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
GEM
|
2
|
-
remote:
|
2
|
+
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
4
|
abstract (1.0.0)
|
5
5
|
actionmailer (3.2.2)
|
@@ -29,7 +29,6 @@ GEM
|
|
29
29
|
activesupport (3.2.2)
|
30
30
|
i18n (~> 0.6)
|
31
31
|
multi_json (~> 1.0)
|
32
|
-
archive-tar-minitar (0.5.2)
|
33
32
|
arel (3.0.2)
|
34
33
|
bcrypt-ruby (3.0.1)
|
35
34
|
bson (1.6.1)
|
@@ -43,7 +42,6 @@ GEM
|
|
43
42
|
xpath (~> 0.1.4)
|
44
43
|
childprocess (0.3.1)
|
45
44
|
ffi (~> 1.0.6)
|
46
|
-
columnize (0.3.6)
|
47
45
|
diff-lcs (1.1.3)
|
48
46
|
erubis (2.7.0)
|
49
47
|
faraday (0.8.4)
|
@@ -59,11 +57,9 @@ GEM
|
|
59
57
|
rake
|
60
58
|
rdoc
|
61
59
|
journey (1.0.3)
|
62
|
-
json (1.
|
60
|
+
json (1.7.7)
|
63
61
|
jwt (0.1.5)
|
64
62
|
multi_json (>= 1.0)
|
65
|
-
linecache19 (0.5.12)
|
66
|
-
ruby_core_source (>= 0.1.4)
|
67
63
|
mail (2.4.4)
|
68
64
|
i18n (>= 0.4.0)
|
69
65
|
mime-types (~> 1.16)
|
@@ -130,16 +126,6 @@ GEM
|
|
130
126
|
activesupport (~> 3.0)
|
131
127
|
railties (~> 3.0)
|
132
128
|
rspec (~> 2.5.0)
|
133
|
-
ruby-debug-base19 (0.11.25)
|
134
|
-
columnize (>= 0.3.1)
|
135
|
-
linecache19 (>= 0.5.11)
|
136
|
-
ruby_core_source (>= 0.1.4)
|
137
|
-
ruby-debug19 (0.11.6)
|
138
|
-
columnize (>= 0.3.1)
|
139
|
-
linecache19 (>= 0.5.11)
|
140
|
-
ruby-debug-base19 (>= 0.11.19)
|
141
|
-
ruby_core_source (0.1.5)
|
142
|
-
archive-tar-minitar (>= 0.5.2)
|
143
129
|
rubyzip (0.9.6.1)
|
144
130
|
selenium-webdriver (2.20.0)
|
145
131
|
childprocess (>= 0.2.5)
|
@@ -154,9 +140,7 @@ GEM
|
|
154
140
|
hike (~> 1.2)
|
155
141
|
rack (~> 1.0)
|
156
142
|
tilt (~> 1.1, != 1.3.0)
|
157
|
-
sqlite3 (1.3.
|
158
|
-
sqlite3-ruby (1.3.3)
|
159
|
-
sqlite3 (>= 1.3.3)
|
143
|
+
sqlite3 (1.3.7)
|
160
144
|
thor (0.14.6)
|
161
145
|
tilt (1.3.3)
|
162
146
|
timecop (0.3.5)
|
@@ -177,7 +161,7 @@ DEPENDENCIES
|
|
177
161
|
bundler (>= 1.1.0)
|
178
162
|
capybara
|
179
163
|
jeweler (~> 1.8.3)
|
180
|
-
json (>= 1.
|
164
|
+
json (>= 1.7.7)
|
181
165
|
mongo_mapper
|
182
166
|
mongoid (~> 2.4.4)
|
183
167
|
oauth (~> 0.4.4)
|
@@ -185,8 +169,7 @@ DEPENDENCIES
|
|
185
169
|
rails (>= 3.0.0)
|
186
170
|
rspec (~> 2.5.0)
|
187
171
|
rspec-rails (~> 2.5.0)
|
188
|
-
ruby-debug19
|
189
172
|
simplecov (>= 0.3.8)
|
190
|
-
sqlite3
|
173
|
+
sqlite3
|
191
174
|
timecop
|
192
175
|
yard (~> 0.6.0)
|
data/README.rdoc
CHANGED
@@ -29,7 +29,7 @@ Railscast: http://railscasts.com/episodes/283-authentication-with-sorcery
|
|
29
29
|
|
30
30
|
Example Rails 3 app using sorcery: https://github.com/NoamB/sorcery-example-app
|
31
31
|
|
32
|
-
Documentation: http://rubydoc.info/gems/sorcery/0.8.
|
32
|
+
Documentation: http://rubydoc.info/gems/sorcery/0.8.2/frames
|
33
33
|
|
34
34
|
Check out the tutorials in the github wiki!
|
35
35
|
|
@@ -182,7 +182,7 @@ Basic HTTP Authentication (see lib/sorcery/controller/submodules/http_basic_auth
|
|
182
182
|
* automatic login is disabled if session key changed.
|
183
183
|
|
184
184
|
Activity Logging (see lib/sorcery/model/submodules/activity_logging.rb):
|
185
|
-
* automatic logging of last login, last logout
|
185
|
+
* automatic logging of last login, last logout, last activity time and IP address for last login.
|
186
186
|
* an easy method of collecting the list of currently logged in users.
|
187
187
|
* configurable timeout by which to decide whether to include a user in the list of logged in users.
|
188
188
|
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.2
|
@@ -26,17 +26,6 @@ Rails.application.config.sorcery.configure do |config|
|
|
26
26
|
#
|
27
27
|
# config.cookie_domain =
|
28
28
|
|
29
|
-
|
30
|
-
# -- remember_me --
|
31
|
-
# allow the remember_me cookie to settable through AJAX
|
32
|
-
# Default: `true`
|
33
|
-
#
|
34
|
-
# user.remember_me_httponly =
|
35
|
-
|
36
|
-
# How long in seconds the session length will be
|
37
|
-
# Default: `604800`
|
38
|
-
#
|
39
|
-
# user.remember_me_for =
|
40
29
|
|
41
30
|
# -- session timeout --
|
42
31
|
# How long in seconds to keep the session alive.
|
@@ -78,7 +67,7 @@ Rails.application.config.sorcery.configure do |config|
|
|
78
67
|
|
79
68
|
|
80
69
|
# -- external --
|
81
|
-
# What providers are supported by this app, i.e. [:twitter, :facebook, :github, :google, :liveid] .
|
70
|
+
# What providers are supported by this app, i.e. [:twitter, :facebook, :github, :linkedin, :xing, :google, :liveid] .
|
82
71
|
# Default: `[]`
|
83
72
|
#
|
84
73
|
# config.external_providers =
|
@@ -100,7 +89,17 @@ Rails.application.config.sorcery.configure do |config|
|
|
100
89
|
# config.linkedin.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=linkedin"
|
101
90
|
# config.linkedin.user_info_fields = ['first-name', 'last-name']
|
102
91
|
# config.linkedin.user_info_mapping = {first_name: "firstName", last_name: "lastName"}
|
103
|
-
# config.linkedin.access_permissions = ['r_basicprofile']
|
92
|
+
# config.linkedin.access_permissions = ['r_basicprofile']
|
93
|
+
#
|
94
|
+
#
|
95
|
+
# For information about XING API:
|
96
|
+
# - user info fields go to https://dev.xing.com/docs/get/users/me
|
97
|
+
#
|
98
|
+
# config.xing.key = ""
|
99
|
+
# config.xing.secret = ""
|
100
|
+
# config.xing.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=xing"
|
101
|
+
# config.xing.user_info_mapping = {first_name: "first_name", last_name: "last_name"}
|
102
|
+
#
|
104
103
|
#
|
105
104
|
# Twitter wil not accept any requests nor redirect uri containing localhost,
|
106
105
|
# make sure you use 0.0.0.0:3000 to access your app in development
|
@@ -217,6 +216,18 @@ Rails.application.config.sorcery.configure do |config|
|
|
217
216
|
# user.subclasses_inherit_config =
|
218
217
|
|
219
218
|
|
219
|
+
# -- remember_me --
|
220
|
+
# allow the remember_me cookie to settable through AJAX
|
221
|
+
# Default: `true`
|
222
|
+
#
|
223
|
+
# user.remember_me_httponly =
|
224
|
+
|
225
|
+
# How long in seconds the session length will be
|
226
|
+
# Default: `604800`
|
227
|
+
#
|
228
|
+
# user.remember_me_for =
|
229
|
+
|
230
|
+
|
220
231
|
# -- user_activation --
|
221
232
|
# the attribute name to hold activation state (active/pending).
|
222
233
|
# Default: `:activation_state`
|
@@ -3,6 +3,7 @@ class SorceryActivityLogging < ActiveRecord::Migration
|
|
3
3
|
add_column :<%= model_class_name.tableize %>, :last_login_at, :datetime, :default => nil
|
4
4
|
add_column :<%= model_class_name.tableize %>, :last_logout_at, :datetime, :default => nil
|
5
5
|
add_column :<%= model_class_name.tableize %>, :last_activity_at, :datetime, :default => nil
|
6
|
+
add_column :<%= model_class_name.tableize %>, :last_login_from_ip_address, :string, :default => nil
|
6
7
|
|
7
8
|
add_index :<%= model_class_name.tableize %>, [:last_logout_at, :last_activity_at]
|
8
9
|
end
|
@@ -10,6 +11,7 @@ class SorceryActivityLogging < ActiveRecord::Migration
|
|
10
11
|
def self.down
|
11
12
|
remove_index :<%= model_class_name.tableize %>, [:last_logout_at, :last_activity_at]
|
12
13
|
|
14
|
+
remove_column :<%= model_class_name.tableize %>, :last_login_from_ip_address
|
13
15
|
remove_column :<%= model_class_name.tableize %>, :last_activity_at
|
14
16
|
remove_column :<%= model_class_name.tableize %>, :last_logout_at
|
15
17
|
remove_column :<%= model_class_name.tableize %>, :last_login_at
|
@@ -19,16 +19,20 @@ module Sorcery
|
|
19
19
|
attr_accessor :register_login_time
|
20
20
|
attr_accessor :register_logout_time
|
21
21
|
attr_accessor :register_last_activity_time
|
22
|
+
attr_accessor :register_last_ip_address
|
22
23
|
|
23
24
|
def merge_activity_logging_defaults!
|
24
25
|
@defaults.merge!(:@register_login_time => true,
|
25
26
|
:@register_logout_time => true,
|
26
|
-
:@register_last_activity_time => true
|
27
|
+
:@register_last_activity_time => true,
|
28
|
+
:@register_last_ip_address => true
|
29
|
+
)
|
27
30
|
end
|
28
31
|
end
|
29
32
|
merge_activity_logging_defaults!
|
30
33
|
end
|
31
34
|
Config.after_login << :register_login_time_to_db
|
35
|
+
Config.after_login << :register_last_ip_address
|
32
36
|
Config.before_logout << :register_logout_time_to_db
|
33
37
|
base.after_filter :register_last_activity_time_to_db
|
34
38
|
end
|
@@ -69,6 +73,13 @@ module Sorcery
|
|
69
73
|
return unless logged_in?
|
70
74
|
current_user.update_single_attribute(current_user.sorcery_config.last_activity_at_attribute_name, Time.now.in_time_zone)
|
71
75
|
end
|
76
|
+
|
77
|
+
# Updates IP address on every login.
|
78
|
+
# This runs as a hook just after a successful login.
|
79
|
+
def register_last_ip_address(user, credentials)
|
80
|
+
return unless Config.register_last_ip_address
|
81
|
+
current_user.update_single_attribute(current_user.sorcery_config.last_login_from_ip_address_name, request.remote_ip)
|
82
|
+
end
|
72
83
|
end
|
73
84
|
end
|
74
85
|
end
|
@@ -10,16 +10,27 @@ module Sorcery
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def get_request_token(token=nil,secret=nil)
|
13
|
-
return ::OAuth::RequestToken.new(get_consumer,token,secret) if token && secret
|
13
|
+
return ::OAuth::RequestToken.new(get_consumer(), token, secret) if token && secret
|
14
|
+
|
14
15
|
get_consumer.get_request_token(:oauth_callback => @callback_url)
|
15
16
|
end
|
16
17
|
|
17
18
|
def authorize_url(args)
|
18
|
-
get_request_token(
|
19
|
+
get_request_token(
|
20
|
+
args[:request_token],
|
21
|
+
args[:request_token_secret]
|
22
|
+
).authorize_url({
|
23
|
+
:oauth_callback => @callback_url
|
24
|
+
})
|
19
25
|
end
|
20
26
|
|
21
27
|
def get_access_token(args)
|
22
|
-
get_request_token(
|
28
|
+
get_request_token(
|
29
|
+
args[:request_token],
|
30
|
+
args[:request_token_secret]
|
31
|
+
).get_access_token({
|
32
|
+
:oauth_verifier => args[:oauth_verifier]
|
33
|
+
})
|
23
34
|
end
|
24
35
|
|
25
36
|
protected
|
@@ -22,7 +22,11 @@ module Sorcery
|
|
22
22
|
client = build_client(options)
|
23
23
|
client.auth_code.get_token(
|
24
24
|
args[:code],
|
25
|
-
{
|
25
|
+
{
|
26
|
+
:redirect_uri => @callback_url,
|
27
|
+
:parse => options.delete(:parse)
|
28
|
+
},
|
29
|
+
options
|
26
30
|
)
|
27
31
|
end
|
28
32
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Sorcery
|
2
|
+
module Controller
|
3
|
+
module Submodules
|
4
|
+
module External
|
5
|
+
module Providers
|
6
|
+
module Base
|
7
|
+
module BaseClient
|
8
|
+
def self.included(base)
|
9
|
+
base.module_eval do
|
10
|
+
class << self
|
11
|
+
attr_accessor :original_callback_url
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -16,7 +16,7 @@ module Sorcery
|
|
16
16
|
base.module_eval do
|
17
17
|
class << self
|
18
18
|
attr_reader :facebook # access to facebook_client.
|
19
|
-
|
19
|
+
|
20
20
|
def merge_facebook_defaults!
|
21
21
|
@defaults.merge!(:@facebook => FacebookClient)
|
22
22
|
end
|
@@ -25,8 +25,9 @@ module Sorcery
|
|
25
25
|
update!
|
26
26
|
end
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
module FacebookClient
|
30
|
+
include Base::BaseClient
|
30
31
|
class << self
|
31
32
|
attr_accessor :key,
|
32
33
|
:secret,
|
@@ -40,7 +41,7 @@ module Sorcery
|
|
40
41
|
attr_reader :access_token
|
41
42
|
|
42
43
|
include Protocols::Oauth2
|
43
|
-
|
44
|
+
|
44
45
|
def init
|
45
46
|
@site = "https://graph.facebook.com"
|
46
47
|
@user_info_path = "/me"
|
@@ -52,19 +53,19 @@ module Sorcery
|
|
52
53
|
@parse = :query
|
53
54
|
@param_name = "access_token"
|
54
55
|
end
|
55
|
-
|
56
|
-
def get_user_hash
|
56
|
+
|
57
|
+
def get_user_hash(access_token)
|
57
58
|
user_hash = {}
|
58
|
-
response =
|
59
|
+
response = access_token.get(@user_info_path)
|
59
60
|
user_hash[:user_info] = JSON.parse(response.body)
|
60
61
|
user_hash[:uid] = user_hash[:user_info]['id']
|
61
62
|
user_hash
|
62
63
|
end
|
63
|
-
|
64
|
+
|
64
65
|
def has_callback?
|
65
66
|
true
|
66
67
|
end
|
67
|
-
|
68
|
+
|
68
69
|
# calculates and returns the url to which the user should be redirected,
|
69
70
|
# to get authenticated at the external provider's site.
|
70
71
|
def login_url(params,session)
|
@@ -82,15 +83,15 @@ module Sorcery
|
|
82
83
|
args = {}
|
83
84
|
options = { :token_url => @token_url, :mode => @mode, :param_name => @param_name, :parse => @parse }
|
84
85
|
args.merge!({:code => params[:code]}) if params[:code]
|
85
|
-
|
86
|
+
return self.get_access_token(args, options)
|
86
87
|
end
|
87
|
-
|
88
|
+
|
88
89
|
end
|
89
90
|
init
|
90
91
|
end
|
91
|
-
|
92
|
+
|
92
93
|
end
|
93
|
-
end
|
94
|
+
end
|
94
95
|
end
|
95
96
|
end
|
96
97
|
end
|
@@ -27,6 +27,7 @@ module Sorcery
|
|
27
27
|
end
|
28
28
|
|
29
29
|
module GithubClient
|
30
|
+
include Base::BaseClient
|
30
31
|
class << self
|
31
32
|
attr_accessor :key,
|
32
33
|
:secret,
|
@@ -50,9 +51,9 @@ module Sorcery
|
|
50
51
|
@user_info_mapping = {}
|
51
52
|
end
|
52
53
|
|
53
|
-
def get_user_hash
|
54
|
+
def get_user_hash(access_token)
|
54
55
|
user_hash = {}
|
55
|
-
response =
|
56
|
+
response = access_token.get(@user_info_path)
|
56
57
|
user_hash[:user_info] = JSON.parse(response.body)
|
57
58
|
user_hash[:uid] = user_hash[:user_info]['id']
|
58
59
|
user_hash
|
@@ -76,7 +77,7 @@ module Sorcery
|
|
76
77
|
:token_url => @token_path,
|
77
78
|
:token_method => :post
|
78
79
|
}
|
79
|
-
|
80
|
+
return self.get_access_token(args, options)
|
80
81
|
end
|
81
82
|
|
82
83
|
end
|
@@ -27,6 +27,7 @@ module Sorcery
|
|
27
27
|
end
|
28
28
|
|
29
29
|
module GoogleClient
|
30
|
+
include Base::BaseClient
|
30
31
|
class << self
|
31
32
|
attr_accessor :key,
|
32
33
|
:secret,
|
@@ -50,9 +51,9 @@ module Sorcery
|
|
50
51
|
@user_info_mapping = {}
|
51
52
|
end
|
52
53
|
|
53
|
-
def get_user_hash
|
54
|
+
def get_user_hash(access_token)
|
54
55
|
user_hash = {}
|
55
|
-
response =
|
56
|
+
response = access_token.get(@user_info_url)
|
56
57
|
user_hash[:user_info] = JSON.parse(response.body)
|
57
58
|
user_hash[:uid] = user_hash[:user_info]['id']
|
58
59
|
user_hash
|
@@ -76,7 +77,7 @@ module Sorcery
|
|
76
77
|
:token_url => @token_url,
|
77
78
|
:token_method => :post
|
78
79
|
}
|
79
|
-
|
80
|
+
return self.get_access_token(args, options)
|
80
81
|
end
|
81
82
|
end
|
82
83
|
init
|
@@ -15,7 +15,7 @@ module Sorcery
|
|
15
15
|
def self.included(base)
|
16
16
|
base.module_eval do
|
17
17
|
class << self
|
18
|
-
attr_reader :linkedin
|
18
|
+
attr_reader :linkedin
|
19
19
|
|
20
20
|
def merge_linkedin_defaults!
|
21
21
|
@defaults.merge!(:@linkedin => LinkedinClient)
|
@@ -25,8 +25,9 @@ module Sorcery
|
|
25
25
|
update!
|
26
26
|
end
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
module LinkedinClient
|
30
|
+
include Base::BaseClient
|
30
31
|
class << self
|
31
32
|
attr_accessor :key,
|
32
33
|
:secret,
|
@@ -42,14 +43,14 @@ module Sorcery
|
|
42
43
|
attr_reader :access_token
|
43
44
|
|
44
45
|
include Protocols::Oauth1
|
45
|
-
|
46
|
+
|
46
47
|
# Override included get_consumer method to provide authorize_path
|
47
48
|
def get_consumer
|
48
49
|
# Add access permissions to request token path
|
49
50
|
@configuration[:request_token_path] += "?scope=" + self.access_permissions.join('+') unless self.access_permissions.blank? or @configuration[:request_token_path].include? "?scope="
|
50
51
|
::OAuth::Consumer.new(@key, @secret, @configuration)
|
51
52
|
end
|
52
|
-
|
53
|
+
|
53
54
|
def init
|
54
55
|
@configuration = {
|
55
56
|
site: "https://api.linkedin.com",
|
@@ -59,20 +60,20 @@ module Sorcery
|
|
59
60
|
}
|
60
61
|
@user_info_path = "/v1/people/~"
|
61
62
|
end
|
62
|
-
|
63
|
-
def get_user_hash
|
63
|
+
|
64
|
+
def get_user_hash(access_token)
|
64
65
|
user_hash = {}
|
65
66
|
fields = self.user_info_fields.join(',')
|
66
|
-
response =
|
67
|
+
response = access_token.get("#{@user_info_path}:(#{fields})", 'x-li-format' => 'json')
|
67
68
|
user_hash[:user_info] = JSON.parse(response.body)
|
68
69
|
user_hash[:uid] = user_hash[:user_info]['id'].to_s
|
69
70
|
user_hash
|
70
71
|
end
|
71
|
-
|
72
|
+
|
72
73
|
def has_callback?
|
73
74
|
true
|
74
75
|
end
|
75
|
-
|
76
|
+
|
76
77
|
# calculates and returns the url to which the user should be redirected,
|
77
78
|
# to get authenticated at the external provider's site.
|
78
79
|
def login_url(params,session)
|
@@ -81,16 +82,16 @@ module Sorcery
|
|
81
82
|
session[:request_token_secret] = req_token.secret
|
82
83
|
self.authorize_url({:request_token => req_token.token, :request_token_secret => req_token.secret})
|
83
84
|
end
|
84
|
-
|
85
|
+
|
85
86
|
# tries to login the user from access token
|
86
87
|
def process_callback(params,session)
|
87
88
|
args = {}
|
88
89
|
args.merge!({:oauth_verifier => params[:oauth_verifier], :request_token => session[:request_token], :request_token_secret => session[:request_token_secret]})
|
89
90
|
args.merge!({:code => params[:code]}) if params[:code]
|
90
|
-
|
91
|
+
return self.get_access_token(args)
|
91
92
|
end
|
92
93
|
|
93
|
-
end
|
94
|
+
end
|
94
95
|
init
|
95
96
|
end
|
96
97
|
end
|
@@ -27,6 +27,7 @@ module Sorcery
|
|
27
27
|
end
|
28
28
|
|
29
29
|
module LiveidClient
|
30
|
+
include Base::BaseClient
|
30
31
|
class << self
|
31
32
|
attr_accessor :key,
|
32
33
|
:secret,
|
@@ -50,10 +51,10 @@ module Sorcery
|
|
50
51
|
@user_info_mapping = {}
|
51
52
|
end
|
52
53
|
|
53
|
-
def get_user_hash
|
54
|
+
def get_user_hash(access_token)
|
54
55
|
user_hash = {}
|
55
|
-
|
56
|
-
response =
|
56
|
+
access_token.token_param = "access_token"
|
57
|
+
response = access_token.get(@user_info_url)
|
57
58
|
user_hash[:user_info] = JSON.parse(response.body)
|
58
59
|
user_hash[:uid] = user_hash[:user_info]['id']
|
59
60
|
user_hash
|
@@ -77,7 +78,7 @@ module Sorcery
|
|
77
78
|
:access_token_path => @token_path,
|
78
79
|
:access_token_method => :post
|
79
80
|
}
|
80
|
-
|
81
|
+
return self.get_access_token(args, options)
|
81
82
|
end
|
82
83
|
end
|
83
84
|
init
|
@@ -18,7 +18,7 @@ module Sorcery
|
|
18
18
|
attr_reader :twitter
|
19
19
|
# def twitter(&blk) # allows block syntax.
|
20
20
|
# yield @twitter
|
21
|
-
# end
|
21
|
+
# end
|
22
22
|
|
23
23
|
def merge_twitter_defaults!
|
24
24
|
@defaults.merge!(:@twitter => TwitterClient)
|
@@ -28,8 +28,9 @@ module Sorcery
|
|
28
28
|
update!
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
module TwitterClient
|
33
|
+
include Base::BaseClient
|
33
34
|
class << self
|
34
35
|
attr_accessor :key,
|
35
36
|
:secret,
|
@@ -40,30 +41,30 @@ module Sorcery
|
|
40
41
|
attr_reader :access_token
|
41
42
|
|
42
43
|
include Protocols::Oauth1
|
43
|
-
|
44
|
+
|
44
45
|
# Override included get_consumer method to provide authorize_path
|
45
46
|
def get_consumer
|
46
47
|
::OAuth::Consumer.new(@key, @secret, :site => @site, :authorize_path => "/oauth/authenticate")
|
47
48
|
end
|
48
|
-
|
49
|
+
|
49
50
|
def init
|
50
51
|
@site = "https://api.twitter.com"
|
51
|
-
@user_info_path = "/1/account/verify_credentials.json"
|
52
|
+
@user_info_path = "/1.1/account/verify_credentials.json"
|
52
53
|
@user_info_mapping = {}
|
53
54
|
end
|
54
|
-
|
55
|
-
def get_user_hash
|
55
|
+
|
56
|
+
def get_user_hash(access_token)
|
56
57
|
user_hash = {}
|
57
|
-
response =
|
58
|
+
response = access_token.get(@user_info_path)
|
58
59
|
user_hash[:user_info] = JSON.parse(response.body)
|
59
60
|
user_hash[:uid] = user_hash[:user_info]['id'].to_s
|
60
61
|
user_hash
|
61
62
|
end
|
62
|
-
|
63
|
+
|
63
64
|
def has_callback?
|
64
65
|
true
|
65
66
|
end
|
66
|
-
|
67
|
+
|
67
68
|
# calculates and returns the url to which the user should be redirected,
|
68
69
|
# to get authenticated at the external provider's site.
|
69
70
|
def login_url(params,session)
|
@@ -72,16 +73,16 @@ module Sorcery
|
|
72
73
|
session[:request_token_secret] = req_token.secret
|
73
74
|
self.authorize_url({:request_token => req_token.token, :request_token_secret => req_token.secret})
|
74
75
|
end
|
75
|
-
|
76
|
+
|
76
77
|
# tries to login the user from access token
|
77
|
-
def process_callback(params,session)
|
78
|
+
def process_callback(params, session)
|
78
79
|
args = {}
|
79
80
|
args.merge!({:oauth_verifier => params[:oauth_verifier], :request_token => session[:request_token], :request_token_secret => session[:request_token_secret]})
|
80
81
|
args.merge!({:code => params[:code]}) if params[:code]
|
81
|
-
|
82
|
+
return self.get_access_token(args)
|
82
83
|
end
|
83
84
|
|
84
|
-
end
|
85
|
+
end
|
85
86
|
init
|
86
87
|
end
|
87
88
|
end
|