cul_omniauth 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2bbef3d6b587426dc435819aae1c1f6840f160b9
4
- data.tar.gz: 26e3cf4f4f3aaca65e525ebf4914407f56d48b75
3
+ metadata.gz: 8d2dab9b5dfce51d5c97dd89c2fcfe267c597ae4
4
+ data.tar.gz: 2ad40620bef5ca4f8b2f5c7a593eca533348af74
5
5
  SHA512:
6
- metadata.gz: 4a0f992990196939a48603a641e515942b0db1d78a1b424bc80f6b6a56705960a4d33a2899a3596c878ac4eaa29c59ece546e02426890431122a1348e5fc6ccc
7
- data.tar.gz: 2f36f41843f1a679a851a012f6ed697be35ff986248ada13e2db7ac7bcf53d12c50045b19f27bd32f549b659a011a4b3fcde1e9cbe22a736c66c866ced4ed111
6
+ metadata.gz: ecc7bfc408966b58c0f29f05a556b48f3767e94ab69a1112bad82e22098bbc2b7f4db2879808f2ac99f1838a07d7bc223a25a12c6bfeb6f02987ec74153fa78d
7
+ data.tar.gz: 69664fda446bab1387bc0e86bbd94dae3340fe527e0c1e42be14942f675ffcf8fddd83bfc298fa01917b21b1395c229fed2c63b46cc573fa44d137711b173c9b
@@ -1,6 +1,10 @@
1
1
  module Cul::Omniauth::AuthorizingController
2
2
  extend ActiveSupport::Concern
3
3
 
4
+ included do
5
+ devise_group :user, contains: [:user]
6
+ end
7
+
4
8
  def store_location
5
9
  session[:return_to] = "#{request.protocol}#{request.host_with_port}#{request.fullpath}"
6
10
  end
@@ -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
- current_user ||= User.send(find_method,request.env["omniauth.auth"], current_user)
20
- affils = ["#{request.env["omniauth.auth"].uid}:users.cul.columbia.edu"]
21
- affils << "staff:cul.columbia.edu" if current_user.respond_to?(:cul_staff?) and current_user.cul_staff?
22
- affils += (request.env["omniauth.auth"].extra.affiliations || [])
23
- affiliations(current_user,affils)
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", :kind => auth_type
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
- session["devise.#{auth_type.downcase}_data"] = request.env["omniauth.auth"]
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
- def find_for_cas(token, resource=nil)
33
- user = where(:uid => token.uid).first
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(:uid => token.uid))
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
- user = where(:uid => token.uid).first
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
- user = where(:uid => token.uid).first
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: auth.provider, uid: auth.uid).first_or_create do |user|
66
- user.email = auth.info.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
 
@@ -1,5 +1,5 @@
1
1
  module Cul
2
2
  module Omniauth
3
- VERSION = "0.4.1"
3
+ VERSION = "0.4.2"
4
4
  end
5
5
  end
@@ -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, 'uid'
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.1
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-13 00:00:00.000000000 Z
11
+ date: 2015-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails