concerto_cas_auth 0.0.3 → 0.0.4
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/README.md +4 -2
- data/app/controllers/concerto_cas_auth/application_controller.rb +35 -8
- data/app/controllers/concerto_cas_auth/omniauth_callback_controller.rb +1 -1
- data/app/views/concerto_cas_auth/omniauth_cas/_signin.html.erb +1 -1
- data/config/initializers/omniauth.rb +29 -9
- data/config/routes.rb +1 -1
- data/lib/concerto_cas_auth.rb +1 -1
- data/lib/concerto_cas_auth/engine.rb +5 -1
- data/lib/concerto_cas_auth/version.rb +1 -1
- data/lib/tasks/concerto_cas_auth_tasks.rake +0 -4
- metadata +2 -3
- data/config/concerto_cas_auth.yml.sample +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3223823ecc987e6217fd13a7b210aacd55d25310
|
4
|
+
data.tar.gz: 5097fa47e1a5963a8e40416e7252de5f9ce8ea41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b433079684eedd9afdc49e3f7fe86d0a4ef6a4b45b608bf7c7146c5926c06a63b321db991fb7859b0606206ae6938d08782f022fe31010bbbe41e7044eedc657
|
7
|
+
data.tar.gz: dc6814cf3b059692f5c8d7bd70b1ff081c677de71bb4e695b667f8ed254fb1217bf24a24f9c6a291f0ace606b0263c08fb95abfa680dfa65683cdb92717a6984
|
data/README.md
CHANGED
@@ -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
|
10
|
+
# Get configuration options for customized CAS return value identifiers
|
8
11
|
omniauth_keys = ConcertoCasAuth::Engine.config.omniauth_keys
|
9
12
|
|
10
|
-
if identity
|
11
|
-
|
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
|
-
|
19
|
-
user
|
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,
|
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
|
-
|
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
|
@@ -1 +1 @@
|
|
1
|
-
<%= link_to 'Log in', 'auth/cas/' %>
|
1
|
+
<%= link_to 'Log in', 'auth/cas/' %>
|
@@ -1,13 +1,33 @@
|
|
1
|
-
#
|
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
|
-
|
4
|
-
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
data/lib/concerto_cas_auth.rb
CHANGED
@@ -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
|
-
|
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
|
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.
|
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-
|
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
|
-
|