sso-auth 0.0.1 → 0.0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/sso_auth/omniauth_callbacks_controller.rb +2 -11
- data/config/locales/en.yml +5 -1
- data/config/locales/ru.yml +4 -0
- data/lib/generators/sso-auth/install/templates/db/migrate/create_permissions.rb +1 -1
- data/lib/sso-auth/engine.rb +21 -4
- data/lib/sso-auth/spec_helper.rb +4 -1
- data/lib/sso-auth/version.rb +1 -1
- metadata +4 -4
@@ -2,17 +2,8 @@
|
|
2
2
|
|
3
3
|
class SsoAuth::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
4
4
|
def identity
|
5
|
-
|
6
|
-
|
7
|
-
attributes = attributes.merge(request.env['omniauth.auth']['info'])
|
8
|
-
attributes.each do |attribute, value|
|
9
|
-
user.send("#{attribute}=", value) if user.respond_to?("#{attribute}=")
|
10
|
-
end
|
11
|
-
user.save(:validate => false)
|
12
|
-
end
|
13
|
-
|
14
|
-
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "системы аутентификации"
|
15
|
-
sign_in user, :event => :authentication
|
5
|
+
sign_in User.find_or_create_by_omniauth_hash(request.env['omniauth.auth']), :event => :authentication
|
6
|
+
flash[:notice] = I18n.t('devise.omniauth_callbacks.success', :kind => I18n.t('sso-auth.provider.title'))
|
16
7
|
redirect_to stored_location_for(:user) || main_app.root_path
|
17
8
|
end
|
18
9
|
|
data/config/locales/en.yml
CHANGED
data/config/locales/ru.yml
CHANGED
@@ -6,6 +6,6 @@ class CreatePermissions < ActiveRecord::Migration
|
|
6
6
|
t.string :role
|
7
7
|
t.timestamps
|
8
8
|
end
|
9
|
-
add_index :permissions, [:user_id, :role, :context_id, :context_type], :name => 'by_user_and_role_and_context'
|
9
|
+
add_index :permissions, [:user_id, :role, :context_id, :context_type], :name => 'by_user_and_role_and_context', :uniq => true
|
10
10
|
end
|
11
11
|
end
|
data/lib/sso-auth/engine.rb
CHANGED
@@ -23,18 +23,22 @@ module SsoAuth
|
|
23
23
|
|
24
24
|
config.to_prepare do
|
25
25
|
ActionController::Base.class_eval do
|
26
|
-
define_singleton_method :
|
26
|
+
define_singleton_method :sso_authenticate_and_authorize do
|
27
27
|
before_filter :authenticate_user!
|
28
|
-
before_filter :
|
29
|
-
load_and_authorize_resource
|
28
|
+
before_filter :authorize_manage_application!
|
30
29
|
rescue_from CanCan::AccessDenied do |exception|
|
31
30
|
render :file => "#{Rails.root}/public/403", :formats => [:html], :status => 403, :layout => false
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
34
|
+
define_singleton_method :sso_load_and_authorize_resource do
|
35
|
+
sso_authenticate_and_authorize
|
36
|
+
load_and_authorize_resource
|
37
|
+
end
|
38
|
+
|
35
39
|
protected
|
36
40
|
|
37
|
-
define_method :
|
41
|
+
define_method :authorize_manage_application! do
|
38
42
|
authorize! :manage, :application
|
39
43
|
end
|
40
44
|
end
|
@@ -56,6 +60,19 @@ module SsoAuth
|
|
56
60
|
define_method :sso_auth_name do
|
57
61
|
email? ? "#{name} <#{email}>" : name
|
58
62
|
end
|
63
|
+
|
64
|
+
define_singleton_method :find_or_create_by_omniauth_hash do |omniauth_hash|
|
65
|
+
user = User.find_by_uid(omniauth_hash[:uid])
|
66
|
+
user ||= User.find_by_email(omniauth_hash[:info][:email]) if omniauth_hash[:info][:email].present?
|
67
|
+
user ||= User.new { |user| user.uid = omniauth_hash[:uid] }
|
68
|
+
attributes = omniauth_hash[:extra][:raw_info][:user] || {}
|
69
|
+
attributes = attributes.merge(omniauth_hash[:info])
|
70
|
+
attributes.each do |attribute, value|
|
71
|
+
user.send("#{attribute}=", value) if user.respond_to?("#{attribute}=")
|
72
|
+
end
|
73
|
+
user.save(:validate => false)
|
74
|
+
user
|
75
|
+
end
|
59
76
|
end
|
60
77
|
|
61
78
|
def self.sso_auth_permission(options)
|
data/lib/sso-auth/spec_helper.rb
CHANGED
@@ -8,7 +8,10 @@ module SsoAuth
|
|
8
8
|
def create_user
|
9
9
|
@sequence ||= 0
|
10
10
|
@sequence += 1
|
11
|
-
User.
|
11
|
+
User.new.tap do |user|
|
12
|
+
user.uid = @sequence
|
13
|
+
user.save(:validate => false)
|
14
|
+
end
|
12
15
|
end
|
13
16
|
|
14
17
|
def user_with_role(role, context=nil, prefix=nil)
|
data/lib/sso-auth/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sso-auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1
|
4
|
+
version: 0.0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cancan
|
@@ -217,7 +217,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
217
217
|
version: '0'
|
218
218
|
segments:
|
219
219
|
- 0
|
220
|
-
hash:
|
220
|
+
hash: 2057994539849800836
|
221
221
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
222
222
|
none: false
|
223
223
|
requirements:
|
@@ -226,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
226
226
|
version: '0'
|
227
227
|
segments:
|
228
228
|
- 0
|
229
|
-
hash:
|
229
|
+
hash: 2057994539849800836
|
230
230
|
requirements: []
|
231
231
|
rubyforge_project:
|
232
232
|
rubygems_version: 1.8.24
|