sorcery 0.8.0 → 0.8.1
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/README.rdoc +1 -1
- data/VERSION +1 -1
- data/lib/generators/sorcery/install_generator.rb +1 -1
- data/lib/generators/sorcery/templates/initializer.rb +9 -0
- data/lib/sorcery/controller/submodules/external/providers/{vkontakte.rb → vk.rb} +25 -20
- data/lib/sorcery/controller/submodules/external.rb +35 -35
- data/lib/sorcery/controller.rb +2 -2
- data/lib/sorcery.rb +1 -1
- data/sorcery.gemspec +3 -3
- metadata +3 -3
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.1/frames
|
33
33
|
|
34
34
|
Check out the tutorials in the github wiki!
|
35
35
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.1
|
@@ -47,7 +47,7 @@ module Sorcery
|
|
47
47
|
|
48
48
|
if submodules
|
49
49
|
submodules.each do |submodule|
|
50
|
-
unless submodule == "http_basic_auth" || submodule == "session_timeout"
|
50
|
+
unless submodule == "http_basic_auth" || submodule == "session_timeout" || submodule == "core"
|
51
51
|
migration_template "migration/#{submodule}.rb", "db/migrate/sorcery_#{submodule}.rb"
|
52
52
|
end
|
53
53
|
end
|
@@ -33,6 +33,10 @@ Rails.application.config.sorcery.configure do |config|
|
|
33
33
|
#
|
34
34
|
# user.remember_me_httponly =
|
35
35
|
|
36
|
+
# How long in seconds the session length will be
|
37
|
+
# Default: `604800`
|
38
|
+
#
|
39
|
+
# user.remember_me_for =
|
36
40
|
|
37
41
|
# -- session timeout --
|
38
42
|
# How long in seconds to keep the session alive.
|
@@ -122,6 +126,11 @@ Rails.application.config.sorcery.configure do |config|
|
|
122
126
|
# config.google.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=google"
|
123
127
|
# config.google.user_info_mapping = {:email => "email", :username => "name"}
|
124
128
|
#
|
129
|
+
# config.vk.key = ""
|
130
|
+
# config.vk.secret = ""
|
131
|
+
# config.vk.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=vk"
|
132
|
+
# config.vk.user_info_mapping = {:login => "domain", :name => "full_name"}
|
133
|
+
#
|
125
134
|
# To use liveid in development mode you have to replace mydomain.com with
|
126
135
|
# a valid domain even in development. To use a valid domain in development
|
127
136
|
# simply add your domain in your /etc/hosts file in front of 127.0.0.1
|
@@ -3,30 +3,30 @@ module Sorcery
|
|
3
3
|
module Submodules
|
4
4
|
module External
|
5
5
|
module Providers
|
6
|
-
# This module adds support for OAuth with
|
7
|
-
# When included in the 'config.providers' option, it adds a new option, 'config.
|
8
|
-
# Via this new option you can configure
|
6
|
+
# This module adds support for OAuth with vk.com.
|
7
|
+
# When included in the 'config.providers' option, it adds a new option, 'config.vk'.
|
8
|
+
# Via this new option you can configure Vk specific settings like your app's key and secret.
|
9
9
|
#
|
10
|
-
# config.
|
11
|
-
# config.
|
10
|
+
# config.vk.key = <key>
|
11
|
+
# config.vk.secret = <secret>
|
12
12
|
# ...
|
13
13
|
#
|
14
|
-
module
|
14
|
+
module Vk
|
15
15
|
def self.included(base)
|
16
16
|
base.module_eval do
|
17
17
|
class << self
|
18
|
-
attr_reader :
|
18
|
+
attr_reader :vk # access to vk_client.
|
19
19
|
|
20
|
-
def
|
21
|
-
@defaults.merge!(:@
|
20
|
+
def merge_vk_defaults!
|
21
|
+
@defaults.merge!(:@vk => VkClient)
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
24
|
+
merge_vk_defaults!
|
25
25
|
update!
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
module
|
29
|
+
module VkClient
|
30
30
|
class << self
|
31
31
|
attr_accessor :key,
|
32
32
|
:secret,
|
@@ -34,8 +34,6 @@ module Sorcery
|
|
34
34
|
:auth_path,
|
35
35
|
:token_path,
|
36
36
|
:site,
|
37
|
-
:scope,
|
38
|
-
:user_info_path,
|
39
37
|
:user_info_mapping
|
40
38
|
attr_reader :access_token
|
41
39
|
|
@@ -43,8 +41,7 @@ module Sorcery
|
|
43
41
|
|
44
42
|
def init
|
45
43
|
@site = "https://oauth.vk.com/"
|
46
|
-
@user_info_url
|
47
|
-
@scope = nil
|
44
|
+
@user_info_url = "https://api.vk.com/method/getProfiles"
|
48
45
|
@auth_path = "/authorize"
|
49
46
|
@token_path = "/access_token"
|
50
47
|
@user_info_mapping = {}
|
@@ -52,12 +49,20 @@ module Sorcery
|
|
52
49
|
|
53
50
|
def get_user_hash
|
54
51
|
user_hash = {}
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
52
|
+
|
53
|
+
params = {
|
54
|
+
:access_token => @access_token.token,
|
55
|
+
:uids => @access_token.params["user_id"],
|
56
|
+
:fields => @user_info_mapping.values.join(",")
|
57
|
+
}
|
58
|
+
|
59
|
+
response = @access_token.get(@user_info_url, :params => params)
|
60
|
+
if user_hash[:user_info] = JSON.parse(response.body)
|
61
|
+
user_hash[:user_info] = user_hash[:user_info]["response"][0]
|
62
|
+
# add full_name - useful if you do not store it in separate fields
|
63
|
+
user_hash[:user_info]["full_name"] = [user_hash[:user_info]["first_name"], user_hash[:user_info]["last_name"]].join(" ")
|
64
|
+
user_hash[:uid] = user_hash[:user_info]["uid"]
|
59
65
|
end
|
60
|
-
user_hash[:uid] = user_hash[:user_info]['user_id']
|
61
66
|
user_hash
|
62
67
|
end
|
63
68
|
|
@@ -31,29 +31,29 @@ module Sorcery
|
|
31
31
|
|
32
32
|
# sends user to authenticate at the provider's website.
|
33
33
|
# after authentication the user is redirected to the callback defined in the provider config
|
34
|
-
def login_at(
|
35
|
-
|
36
|
-
if
|
34
|
+
def login_at(provider_name, args = {})
|
35
|
+
provider = Config.send(provider_name)
|
36
|
+
if provider.callback_url.present? && provider.callback_url[0] == '/'
|
37
37
|
uri = URI.parse(request.url.gsub(/\?.*$/,''))
|
38
38
|
uri.path = ''
|
39
39
|
uri.query = nil
|
40
40
|
uri.scheme = 'https' if(request.env['HTTP_X_FORWARDED_PROTO'] == 'https')
|
41
41
|
host = uri.to_s
|
42
|
-
|
42
|
+
provider.callback_url = "#{host}#{provider.callback_url}"
|
43
43
|
end
|
44
|
-
if
|
45
|
-
redirect_to
|
44
|
+
if provider.has_callback?
|
45
|
+
redirect_to provider.login_url(params,session)
|
46
46
|
else
|
47
|
-
|
47
|
+
#provider.login(args)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
# tries to login the user from provider's callback
|
52
|
-
def login_from(
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
if user = user_class.load_from_provider(
|
52
|
+
def login_from(provider_name)
|
53
|
+
provider = Config.send(provider_name)
|
54
|
+
provider.process_callback(params,session)
|
55
|
+
user_hash = provider.get_user_hash
|
56
|
+
if user = user_class.load_from_provider(provider_name,user_hash[:uid].to_s)
|
57
57
|
return_to_url = session[:return_to_url]
|
58
58
|
reset_session
|
59
59
|
session[:return_to_url] = return_to_url
|
@@ -64,22 +64,22 @@ module Sorcery
|
|
64
64
|
end
|
65
65
|
|
66
66
|
# get provider access account
|
67
|
-
def access_token(
|
68
|
-
|
69
|
-
|
67
|
+
def access_token(provider_name)
|
68
|
+
provider = Config.send(provider_name)
|
69
|
+
provider.access_token
|
70
70
|
end
|
71
71
|
|
72
72
|
# If user is logged, he can add all available providers into his account
|
73
|
-
def add_provider_to_user(
|
74
|
-
provider_name =
|
75
|
-
|
76
|
-
|
77
|
-
|
73
|
+
def add_provider_to_user(provider_name)
|
74
|
+
provider_name = provider_name.to_sym
|
75
|
+
provider = Config.send(provider_name)
|
76
|
+
provider.process_callback(params,session)
|
77
|
+
user_hash = provider.get_user_hash
|
78
78
|
config = user_class.sorcery_config
|
79
79
|
|
80
80
|
# first check to see if user has a particular authentication already
|
81
|
-
unless (current_user.send(config.authentications_class.to_s.downcase.pluralize).send("find_by_#{config.provider_attribute_name}_and_#{config.provider_uid_attribute_name}",
|
82
|
-
user = current_user.send(config.authentications_class.to_s.downcase.pluralize).build(config.provider_uid_attribute_name =>
|
81
|
+
unless (current_user.send(config.authentications_class.to_s.downcase.pluralize).send("find_by_#{config.provider_attribute_name}_and_#{config.provider_uid_attribute_name}", provider_name, user_hash[:uid].to_s))
|
82
|
+
user = current_user.send(config.authentications_class.to_s.downcase.pluralize).build(config.provider_uid_attribute_name => user_hash[:uid], config.provider_attribute_name => provider_name.to_s)
|
83
83
|
user.save(:validate => false)
|
84
84
|
else
|
85
85
|
user = false
|
@@ -91,19 +91,19 @@ module Sorcery
|
|
91
91
|
# Initialize new user from provider informations.
|
92
92
|
# If a provider doesn't give required informations or username/email is already taken,
|
93
93
|
# we store provider/user infos into a session and can be rendered into registration form
|
94
|
-
def create_and_validate_from(
|
95
|
-
|
96
|
-
|
97
|
-
|
94
|
+
def create_and_validate_from(provider_name)
|
95
|
+
provider_name = provider_name.to_sym
|
96
|
+
provider = Config.send(provider_name)
|
97
|
+
user_hash = provider.get_user_hash
|
98
98
|
config = user_class.sorcery_config
|
99
99
|
|
100
|
-
attrs = user_attrs(
|
100
|
+
attrs = user_attrs(provider.user_info_mapping, user_hash)
|
101
101
|
|
102
102
|
user = user_class.new(attrs)
|
103
|
-
user.send(config.authentications_class.to_s.downcase.pluralize).build(config.provider_uid_attribute_name =>
|
103
|
+
user.send(config.authentications_class.to_s.downcase.pluralize).build(config.provider_uid_attribute_name => user_hash[:uid], config.provider_attribute_name => provider_name)
|
104
104
|
|
105
105
|
session[:incomplete_user] = {
|
106
|
-
:provider => {config.provider_uid_attribute_name =>
|
106
|
+
:provider => {config.provider_uid_attribute_name => user_hash[:uid], config.provider_attribute_name => provider_name},
|
107
107
|
:user_hash => attrs
|
108
108
|
} unless user.save
|
109
109
|
|
@@ -126,13 +126,13 @@ module Sorcery
|
|
126
126
|
#
|
127
127
|
# create_from(provider) {|user| user.some_check }
|
128
128
|
#
|
129
|
-
def create_from(
|
130
|
-
|
131
|
-
|
132
|
-
|
129
|
+
def create_from(provider_name)
|
130
|
+
provider_name = provider_name.to_sym
|
131
|
+
provider = Config.send(provider_name)
|
132
|
+
user_hash = provider.get_user_hash
|
133
133
|
config = user_class.sorcery_config
|
134
134
|
|
135
|
-
attrs = user_attrs(
|
135
|
+
attrs = user_attrs(provider.user_info_mapping, user_hash)
|
136
136
|
|
137
137
|
user_class.transaction do
|
138
138
|
@user = user_class.new()
|
@@ -145,7 +145,7 @@ module Sorcery
|
|
145
145
|
end
|
146
146
|
|
147
147
|
@user.save(:validate => false)
|
148
|
-
user_class.sorcery_config.authentications_class.create!({config.authentications_user_id_attribute_name => @user.id, config.provider_attribute_name =>
|
148
|
+
user_class.sorcery_config.authentications_class.create!({config.authentications_user_id_attribute_name => @user.id, config.provider_attribute_name => provider_name, config.provider_uid_attribute_name => user_hash[:uid]})
|
149
149
|
end
|
150
150
|
@user
|
151
151
|
end
|
data/lib/sorcery/controller.rb
CHANGED
@@ -32,9 +32,9 @@ module Sorcery
|
|
32
32
|
@current_user = nil
|
33
33
|
user = user_class.authenticate(*credentials)
|
34
34
|
if user
|
35
|
-
old_session = session.dup
|
35
|
+
old_session = session.dup.to_hash
|
36
36
|
reset_session # protect from session fixation attacks
|
37
|
-
old_session.
|
37
|
+
old_session.each_pair do |k,v|
|
38
38
|
session[k.to_sym] = v
|
39
39
|
end
|
40
40
|
auto_login(user)
|
data/lib/sorcery.rb
CHANGED
@@ -37,7 +37,7 @@ module Sorcery
|
|
37
37
|
autoload :Google, 'sorcery/controller/submodules/external/providers/google'
|
38
38
|
autoload :Liveid, 'sorcery/controller/submodules/external/providers/liveid'
|
39
39
|
autoload :Linkedin, 'sorcery/controller/submodules/external/providers/linkedin'
|
40
|
-
autoload :
|
40
|
+
autoload :Vk, 'sorcery/controller/submodules/external/providers/vk'
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
data/sorcery.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "sorcery"
|
8
|
-
s.version = "0.8.
|
8
|
+
s.version = "0.8.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Noam Ben Ari"]
|
12
|
-
s.date = "2013-01-
|
12
|
+
s.date = "2013-01-25"
|
13
13
|
s.description = "Provides common authentication needs such as signing in/out, activating by email and resetting password."
|
14
14
|
s.email = "nbenari@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -50,7 +50,7 @@ Gem::Specification.new do |s|
|
|
50
50
|
"lib/sorcery/controller/submodules/external/providers/linkedin.rb",
|
51
51
|
"lib/sorcery/controller/submodules/external/providers/liveid.rb",
|
52
52
|
"lib/sorcery/controller/submodules/external/providers/twitter.rb",
|
53
|
-
"lib/sorcery/controller/submodules/external/providers/
|
53
|
+
"lib/sorcery/controller/submodules/external/providers/vk.rb",
|
54
54
|
"lib/sorcery/controller/submodules/http_basic_auth.rb",
|
55
55
|
"lib/sorcery/controller/submodules/remember_me.rb",
|
56
56
|
"lib/sorcery/controller/submodules/session_timeout.rb",
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: sorcery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.8.
|
5
|
+
version: 0.8.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Noam Ben Ari
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2013-01-
|
13
|
+
date: 2013-01-25 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: oauth
|
@@ -253,7 +253,7 @@ files:
|
|
253
253
|
- lib/sorcery/controller/submodules/external/providers/linkedin.rb
|
254
254
|
- lib/sorcery/controller/submodules/external/providers/liveid.rb
|
255
255
|
- lib/sorcery/controller/submodules/external/providers/twitter.rb
|
256
|
-
- lib/sorcery/controller/submodules/external/providers/
|
256
|
+
- lib/sorcery/controller/submodules/external/providers/vk.rb
|
257
257
|
- lib/sorcery/controller/submodules/http_basic_auth.rb
|
258
258
|
- lib/sorcery/controller/submodules/remember_me.rb
|
259
259
|
- lib/sorcery/controller/submodules/session_timeout.rb
|