concerto_cas_auth 0.0.3 → 0.0.4

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: fdead88154ae16c333b27754faaa318274680422
4
- data.tar.gz: 6dec16c4284ee3337f7ab968024d22ee2e8bd133
3
+ metadata.gz: 3223823ecc987e6217fd13a7b210aacd55d25310
4
+ data.tar.gz: 5097fa47e1a5963a8e40416e7252de5f9ce8ea41
5
5
  SHA512:
6
- metadata.gz: 2159ae71680cbef73cbdd6ab0440336ef941926b0250011e6f68baae7b62a8f487e87ecc19fc9ea978e71430e566997becf3338e4eb261cf63c2b8276ead64e0
7
- data.tar.gz: 767ce53a20716e5327ebf329dff78f3fb14b0b2c755a0c3e21a66b799912d729d008347fb8b021773fd32033012920ed1d25f5e1fcfbf2de2114576428ccd470
6
+ metadata.gz: b433079684eedd9afdc49e3f7fe86d0a4ef6a4b45b608bf7c7146c5926c06a63b321db991fb7859b0606206ae6938d08782f022fe31010bbbe41e7044eedc657
7
+ data.tar.gz: dc6814cf3b059692f5c8d7bd70b1ff081c677de71bb4e695b667f8ed254fb1217bf24a24f9c6a291f0ace606b0263c08fb95abfa680dfa65683cdb92717a6984
data/README.md CHANGED
@@ -1,2 +1,4 @@
1
- ConcertoCasAuth
2
- ===============
1
+ Concerto CAS Auth
2
+ =====================
3
+
4
+ Authenticate Concerto users through your own [CAS](http://en.wikipedia.org/wiki/Central_Authentication_Service) deployment.
@@ -1,25 +1,42 @@
1
1
  module ConcertoCasAuth
2
2
  class ApplicationController < ::ApplicationController
3
3
 
4
+ # Used to map a user id with a corresponding authentication provider in the
5
+ # database (in this case it's CAS)
4
6
  require 'concerto_identity'
5
7
 
8
+ # Find or create a new user based on values returned by the CAS callback
6
9
  def find_from_omniauth(cas_hash)
7
- # Get any configuration options for customized CAS return value identifiers
10
+ # Get configuration options for customized CAS return value identifiers
8
11
  omniauth_keys = ConcertoCasAuth::Engine.config.omniauth_keys
9
12
 
10
- if identity = ConcertoIdentity::Identity.find_by_user_id(cas_hash[omniauth_keys["uid_key"]])
11
- # Check if user already exists
13
+ # Check if an identity records exists for the user attempting to sign in
14
+ if identity = ConcertoIdentity::Identity.find_by_user_id(
15
+ cas_hash[omniauth_keys["uid_key"]])
16
+ # Return the matching user record
12
17
  return identity.user
13
18
  else
14
19
  # Add a new user via omniauth cas details
15
20
  user = User.new
16
21
 
17
22
  # Set user attributes
18
- user.is_admin = false
19
- user.first_name = cas_hash[omniauth_keys["first_name_key"]]
23
+
24
+ # First name is required for user validation
25
+ if !cas_hash[omniauth_keys["first_name_key"]].nil?
26
+ user.first_name = cas_hash[omniauth_keys["first_name_key"]]
27
+ else
28
+ user.first_name = cas_hash[omniauth_keys["uid_key"]]
29
+ end
30
+
31
+ # Email is required for user validation
20
32
  user.email = cas_hash[omniauth_keys["email_key"]]
21
- user.password, user.password_confirmation = Devise.friendly_token.first(8)
22
33
 
34
+ # Set user admin flag to false
35
+ user.is_admin = false
36
+ # Set user password and confirmation to random tokens
37
+ user.password,user.password_confirmation=Devise.friendly_token.first(8)
38
+
39
+ # Check if this is our application's first user
23
40
  if !User.exists?
24
41
  # First user is an admin
25
42
  first_user_setup = true
@@ -37,13 +54,23 @@ module ConcertoCasAuth
37
54
 
38
55
  # Create Concerto Admin Group
39
56
  group = Group.where(:name => "Concerto Admins").first_or_create
40
- membership = Membership.create(:user_id => user.id, :group_id => group.id, :level => Membership::LEVELS[:leader])
57
+ membership = Membership.create(:user_id => user.id,
58
+ :group_id => group.id,
59
+ :level => Membership::LEVELS[:leader])
41
60
  end
42
61
 
62
+ # Attempt to save our new user
43
63
  if user.save
44
- ConcertoIdentity::Identity.create(provider: "cas", external_id: cash_hash[omniauth_keys["uid_key"]], user_id: user.id)
64
+ # Create a matching identity to track our new user for future
65
+ # sessions and return our new user record
66
+ ConcertoIdentity::Identity.create(provider: "cas",
67
+ external_id: cash_hash[omniauth_keys["uid_key"]],
68
+ user_id: user.id)
45
69
  return user
46
70
  else
71
+ # User save failed, an error occurred
72
+ flash.notice = "Failed to sign in with CAS.
73
+ #{user.errors.full_messages.to_sentence}."
47
74
  return nil
48
75
  end
49
76
  end
@@ -8,7 +8,7 @@ module ConcertoCasAuth
8
8
  user = find_from_omniauth(cas_hash)
9
9
 
10
10
  if !user
11
- flash.notice = "Failed to sign in with CAS"
11
+ # Redirect showing flash notice with errors
12
12
  redirect_to "/"
13
13
  elsif user.persisted?
14
14
  flash.notice = "Signed in through CAS"
@@ -1 +1 @@
1
- <%= link_to 'Log in', 'auth/cas/' %>
1
+ <%= link_to 'Log in', 'auth/cas/' %>
@@ -1,13 +1,33 @@
1
- # Initializer for omniauth-cas gem
1
+ # Concerto Configs are created if they don't exist already
2
+ # these are used to initialize and configure omniauth-cas
3
+ ConcertoConfig.make_concerto_config("cas_url", "https://cas.example.org/cas",
4
+ :value_type => "string",
5
+ :value_default => "https://cas.example.org/cas",
6
+ :category => 'CAS User Authentication',
7
+ :seq_no => 1,
8
+ :description =>"Defines the url of your CAS server")
2
9
 
3
- # get yml config from main Concerto application in config directory
4
- raw_config = YAML.load_file("#{Rails.root.to_s}/config/concerto_cas_auth.yml")
10
+ ConcertoConfig.make_concerto_config("cas_uid_key", "user",
11
+ :value_type => "string",
12
+ :value_default => "user",
13
+ :category => 'CAS User Authentication',
14
+ :seq_no => 2,
15
+ :description =>'The CAS field name containing user login names (uid, username,email,etc)')
5
16
 
6
- # read all available configuration options from yml file
7
- omniauth_config = {}
8
- raw_config.each do |key, value|
9
- omniauth_config[key] = value
10
- end
17
+ ConcertoConfig.make_concerto_config("cas_email_key", "email",
18
+ :value_type => "string",
19
+ :value_default => "email",
20
+ :category => 'CAS User Authentication',
21
+ :seq_no => 3,
22
+ :description =>'The CAS field name containing user email addresses (email, uid,etc)')
23
+
24
+ # Store omniauth config values from main application's ConcertoConfig
25
+ omniauth_config = {
26
+ :host => URI.parse(ConcertoConfig[:cas_url]).host,
27
+ :url => ConcertoConfig[:cas_url],
28
+ :uid_key => ConcertoConfig[:cas_uid_key],
29
+ :email_key => ConcertoConfig[:cas_email_key]
30
+ }
11
31
 
12
32
  # configure omniauth-cas gem based on specified yml configs
13
33
  Rails.application.config.middleware.use OmniAuth::Builder do
@@ -18,4 +38,4 @@ end
18
38
  # to reference any unique identifiers for extra CAS options
19
39
  ConcertoCasAuth::Engine.configure do
20
40
  config.omniauth_keys = omniauth_config
21
- end
41
+ end
data/config/routes.rb CHANGED
@@ -4,4 +4,4 @@ end
4
4
 
5
5
  ConcertoCasAuth::Engine.routes.draw do
6
6
  get ":provider/callback", :to => "omniauth_callback#cas_auth"
7
- end
7
+ end
@@ -1,4 +1,4 @@
1
1
  require "concerto_cas_auth/engine"
2
2
 
3
3
  module ConcertoCasAuth
4
- end
4
+ end
@@ -13,11 +13,15 @@ module ConcertoCasAuth
13
13
  def plugin_info(plugin_info_class)
14
14
  @plugin_info ||= plugin_info_class.new do
15
15
 
16
+ # Add our concerto_cas_auth route to the main application
16
17
  add_route("concerto_cas_auth", ConcertoCasAuth::Engine)
17
18
 
18
- add_view_hook "ApplicationController", :signin_hook, :partial => "concerto_cas_auth/omniauth_cas/signin"
19
+ # View hook to override Devise sign in links in the main application
20
+ add_view_hook "ApplicationController", :signin_hook,
21
+ :partial => "concerto_cas_auth/omniauth_cas/signin"
19
22
 
20
23
  end
21
24
  end
25
+
22
26
  end
23
27
  end
@@ -1,3 +1,3 @@
1
1
  module ConcertoCasAuth
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :concerto_cas_auth do
3
- # # Task goes here
4
- # end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: concerto_cas_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabe Perez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-25 00:00:00.000000000 Z
11
+ date: 2014-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -65,7 +65,6 @@ files:
65
65
  - app/controllers/concerto_cas_auth/omniauth_callback_controller.rb
66
66
  - app/helpers/concerto_cas_auth/application_helper.rb
67
67
  - app/views/concerto_cas_auth/omniauth_cas/_signin.html.erb
68
- - config/concerto_cas_auth.yml.sample
69
68
  - config/initializers/omniauth.rb
70
69
  - config/routes.rb
71
70
  - lib/concerto_cas_auth/engine.rb
@@ -1,39 +0,0 @@
1
- # ============================================================
2
- # THIS FILE GOES IN THE CONCERTO APPLICATION CONFIG/ DIRECTORY
3
- # ============================================================
4
-
5
- # Configuration options for omniauth-cas
6
- # visit https://github.com/dlindahl/omniauth-cas
7
- # for more details in README
8
-
9
- # ----------------
10
- # Required options
11
- # ----------------
12
- # host:
13
- # url:
14
-
15
- # -----------------------------------------------
16
- # Configurable options for values returned by CAS
17
- # -----------------------------------------------
18
- # uid_key:
19
- # name_key:
20
- # email_key:
21
- # first_name_key:
22
- # last_name_key:
23
- # location_key:
24
- # image_key:
25
- # phone_key:
26
-
27
- # --------------------------
28
- # Other configurable options
29
- # --------------------------
30
- # port:
31
- # ssl:
32
- # service_validate_url:
33
- # logout_url:
34
- # login_url:
35
- # uid_field:
36
- # ca_path:
37
- # disable_ssl_verification:
38
- # on_single_sign_out:
39
-