cul_omniauth 0.4.1 → 0.4.2
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/app/controllers/concerns/cul/omniauth/authorizing_controller.rb +4 -0
- data/app/controllers/concerns/cul/omniauth/callbacks.rb +17 -9
- data/app/models/concerns/cul/omniauth/users.rb +13 -23
- data/lib/cul/omniauth/version.rb +1 -1
- data/lib/omni_auth/strategies/saml.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d2dab9b5dfce51d5c97dd89c2fcfe267c597ae4
|
4
|
+
data.tar.gz: 2ad40620bef5ca4f8b2f5c7a593eca533348af74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecc7bfc408966b58c0f29f05a556b48f3767e94ab69a1112bad82e22098bbc2b7f4db2879808f2ac99f1838a07d7bc223a25a12c6bfeb6f02987ec74153fa78d
|
7
|
+
data.tar.gz: 69664fda446bab1387bc0e86bbd94dae3340fe527e0c1e42be14942f675ffcf8fddd83bfc298fa01917b21b1395c229fed2c63b46cc573fa44d137711b173c9b
|
@@ -1,5 +1,8 @@
|
|
1
1
|
module Cul::Omniauth::Callbacks
|
2
2
|
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
OMNIAUTH_REQUEST_KEY = 'omniauth.auth'.freeze
|
5
|
+
|
3
6
|
def cas
|
4
7
|
find_user('CAS')
|
5
8
|
end
|
@@ -16,17 +19,22 @@ module Cul::Omniauth::Callbacks
|
|
16
19
|
|
17
20
|
def find_user(auth_type)
|
18
21
|
find_method = "find_for_#{auth_type.downcase}".to_sym
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
affils
|
23
|
-
|
22
|
+
# omniauth puts a hash of information with string keys in the request env
|
23
|
+
oa_data = request.env.fetch(OMNIAUTH_REQUEST_KEY,{})
|
24
|
+
@current_user ||= User.send(find_method,oa_data, @current_user)
|
25
|
+
affils = ["#{oa_data['uid']}:users.cul.columbia.edu"]
|
26
|
+
affils << "staff:cul.columbia.edu" if @current_user.respond_to?(:cul_staff?) and @current_user.cul_staff?
|
27
|
+
affils += (oa_data.fetch('extra',{})['affiliations'] || [])
|
28
|
+
affiliations(@current_user,affils)
|
24
29
|
session["devise.roles"] = affils
|
25
|
-
if current_user.persisted?
|
26
|
-
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :
|
27
|
-
sign_in_and_redirect current_user, :event => :authentication
|
30
|
+
if @current_user && @current_user.persisted?
|
31
|
+
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", kind: auth_type
|
32
|
+
sign_in_and_redirect @current_user, :event => :authentication
|
28
33
|
else
|
29
|
-
|
34
|
+
reason = @current_user ? 'no persisted user for id' : 'no uid in token'
|
35
|
+
Rails.logger.warn("#{reason} #{oa_data.inspect}")
|
36
|
+
flash[:notice] = I18n.t "devise.omniauth_callbacks.failure", kind: auth_type, reason: reason
|
37
|
+
session["devise.#{auth_type.downcase}_data"] = oa_data
|
30
38
|
redirect_to root_url
|
31
39
|
end
|
32
40
|
end
|
@@ -29,44 +29,34 @@ module Cul::Omniauth::Users
|
|
29
29
|
end
|
30
30
|
|
31
31
|
module ClassMethods
|
32
|
-
|
33
|
-
|
32
|
+
# token is an omniauth hash
|
33
|
+
def find_for_provider(token, provider)
|
34
|
+
return nil unless token['uid']
|
35
|
+
props = {:uid => token['uid'].downcase, provider: provider.downcase}
|
36
|
+
user = where(props).first
|
34
37
|
# create new user if necessary
|
35
38
|
unless user
|
36
|
-
user = create(whitelist(
|
39
|
+
user = create!(whitelist(props))
|
37
40
|
# can we add groups or roles here?
|
38
41
|
end
|
39
42
|
user
|
40
43
|
end
|
44
|
+
def find_for_cas(token, resource=nil)
|
45
|
+
find_for_provider(token, 'cas')
|
46
|
+
end
|
41
47
|
|
42
48
|
def find_for_saml(token, resource=nil)
|
43
|
-
|
44
|
-
# create new user if necessary
|
45
|
-
unless user
|
46
|
-
user = create(whitelist(:uid => token.uid))
|
47
|
-
# can we add groups or roles here?
|
48
|
-
end
|
49
|
-
|
50
|
-
user
|
49
|
+
find_for_provider(token, 'saml')
|
51
50
|
end
|
52
51
|
|
53
52
|
def find_for_wind(token, resource=nil)
|
54
|
-
|
55
|
-
# create new user if necessary
|
56
|
-
unless user
|
57
|
-
user = create(whitelist(:uid => token.uid))
|
58
|
-
# can we add groups or roles here?
|
59
|
-
end
|
60
|
-
|
61
|
-
user
|
53
|
+
find_for_provider(token, 'wind')
|
62
54
|
end
|
63
55
|
|
64
56
|
def from_omniauth(auth)
|
65
|
-
where(provider:
|
66
|
-
user.email =
|
57
|
+
where(provider: token['provider'].downcase, uid: token['uid'].downcase).first_or_create do |user|
|
58
|
+
user.email = token['info']['email']
|
67
59
|
user.password = Devise.friendly_token[0,20]
|
68
|
-
user.name = auth.info.name # assuming the user model has a name
|
69
|
-
user.image = auth.info.image # assuming the user model has an image
|
70
60
|
end
|
71
61
|
end
|
72
62
|
|
data/lib/cul/omniauth/version.rb
CHANGED
@@ -43,7 +43,7 @@ module OmniAuth
|
|
43
43
|
# @return [Hash] Extra user info
|
44
44
|
option :fetch_raw_info, Proc.new { Hash.new }
|
45
45
|
# Make all the keys configurable with some defaults set here
|
46
|
-
option :uid_field, '
|
46
|
+
option :uid_field, 'user'
|
47
47
|
option :name_key, 'name'
|
48
48
|
option :email_key, 'email'
|
49
49
|
option :nickname_key, 'user'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cul_omniauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- barmintor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|