Skip to content

Commit 716735b

Browse files
committed
feat: update the engine to create users and apps in an isolated
1 parent 06bdbc5 commit 716735b

23 files changed

+615
-10
lines changed

Gemfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
# frozen_string_literal: true
2+
13
source 'https://rubygems.org'
24
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
35

46
# Specify your gem's dependencies in coco_auth.gemspec.
57
gemspec
68

79
group :development do
8-
gem 'sqlite3'
10+
gem 'bcrypt', '~> 3.1.7'
11+
gem 'bootsnap', require: false
12+
gem 'sqlite3', '~> 1.4'
913
end
1014

1115
# To use a debugger

Gemfile.lock

+174
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
PATH
2+
remote: .
3+
specs:
4+
coco_auth (0.1.0)
5+
rails (~> 6.1.7, >= 6.1.7.7)
6+
ruby-saml (~> 1.11)
7+
sqlite3 (~> 1.4)
8+
9+
GEM
10+
remote: https://rubygems.org/
11+
specs:
12+
actioncable (6.1.7.7)
13+
actionpack (= 6.1.7.7)
14+
activesupport (= 6.1.7.7)
15+
nio4r (~> 2.0)
16+
websocket-driver (>= 0.6.1)
17+
actionmailbox (6.1.7.7)
18+
actionpack (= 6.1.7.7)
19+
activejob (= 6.1.7.7)
20+
activerecord (= 6.1.7.7)
21+
activestorage (= 6.1.7.7)
22+
activesupport (= 6.1.7.7)
23+
mail (>= 2.7.1)
24+
actionmailer (6.1.7.7)
25+
actionpack (= 6.1.7.7)
26+
actionview (= 6.1.7.7)
27+
activejob (= 6.1.7.7)
28+
activesupport (= 6.1.7.7)
29+
mail (~> 2.5, >= 2.5.4)
30+
rails-dom-testing (~> 2.0)
31+
actionpack (6.1.7.7)
32+
actionview (= 6.1.7.7)
33+
activesupport (= 6.1.7.7)
34+
rack (~> 2.0, >= 2.0.9)
35+
rack-test (>= 0.6.3)
36+
rails-dom-testing (~> 2.0)
37+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
38+
actiontext (6.1.7.7)
39+
actionpack (= 6.1.7.7)
40+
activerecord (= 6.1.7.7)
41+
activestorage (= 6.1.7.7)
42+
activesupport (= 6.1.7.7)
43+
nokogiri (>= 1.8.5)
44+
actionview (6.1.7.7)
45+
activesupport (= 6.1.7.7)
46+
builder (~> 3.1)
47+
erubi (~> 1.4)
48+
rails-dom-testing (~> 2.0)
49+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
50+
activejob (6.1.7.7)
51+
activesupport (= 6.1.7.7)
52+
globalid (>= 0.3.6)
53+
activemodel (6.1.7.7)
54+
activesupport (= 6.1.7.7)
55+
activerecord (6.1.7.7)
56+
activemodel (= 6.1.7.7)
57+
activesupport (= 6.1.7.7)
58+
activestorage (6.1.7.7)
59+
actionpack (= 6.1.7.7)
60+
activejob (= 6.1.7.7)
61+
activerecord (= 6.1.7.7)
62+
activesupport (= 6.1.7.7)
63+
marcel (~> 1.0)
64+
mini_mime (>= 1.1.0)
65+
activesupport (6.1.7.7)
66+
concurrent-ruby (~> 1.0, >= 1.0.2)
67+
i18n (>= 1.6, < 2)
68+
minitest (>= 5.1)
69+
tzinfo (~> 2.0)
70+
zeitwerk (~> 2.3)
71+
bcrypt (3.1.20)
72+
bootsnap (1.18.3)
73+
msgpack (~> 1.2)
74+
builder (3.2.4)
75+
concurrent-ruby (1.2.3)
76+
crass (1.0.6)
77+
date (3.3.4)
78+
erubi (1.12.0)
79+
globalid (1.2.1)
80+
activesupport (>= 6.1)
81+
i18n (1.14.5)
82+
concurrent-ruby (~> 1.0)
83+
loofah (2.22.0)
84+
crass (~> 1.0.2)
85+
nokogiri (>= 1.12.0)
86+
mail (2.8.1)
87+
mini_mime (>= 0.1.1)
88+
net-imap
89+
net-pop
90+
net-smtp
91+
marcel (1.0.4)
92+
method_source (1.1.0)
93+
mini_mime (1.1.5)
94+
minitest (5.23.1)
95+
msgpack (1.7.2)
96+
net-imap (0.4.11)
97+
date
98+
net-protocol
99+
net-pop (0.1.2)
100+
net-protocol
101+
net-protocol (0.2.2)
102+
timeout
103+
net-smtp (0.5.0)
104+
net-protocol
105+
nio4r (2.7.3)
106+
nokogiri (1.16.5-arm64-darwin)
107+
racc (~> 1.4)
108+
racc (1.8.0)
109+
rack (2.2.9)
110+
rack-test (2.1.0)
111+
rack (>= 1.3)
112+
rails (6.1.7.7)
113+
actioncable (= 6.1.7.7)
114+
actionmailbox (= 6.1.7.7)
115+
actionmailer (= 6.1.7.7)
116+
actionpack (= 6.1.7.7)
117+
actiontext (= 6.1.7.7)
118+
actionview (= 6.1.7.7)
119+
activejob (= 6.1.7.7)
120+
activemodel (= 6.1.7.7)
121+
activerecord (= 6.1.7.7)
122+
activestorage (= 6.1.7.7)
123+
activesupport (= 6.1.7.7)
124+
bundler (>= 1.15.0)
125+
railties (= 6.1.7.7)
126+
sprockets-rails (>= 2.0.0)
127+
rails-dom-testing (2.2.0)
128+
activesupport (>= 5.0.0)
129+
minitest
130+
nokogiri (>= 1.6)
131+
rails-html-sanitizer (1.6.0)
132+
loofah (~> 2.21)
133+
nokogiri (~> 1.14)
134+
railties (6.1.7.7)
135+
actionpack (= 6.1.7.7)
136+
activesupport (= 6.1.7.7)
137+
method_source
138+
rake (>= 12.2)
139+
thor (~> 1.0)
140+
rake (13.2.1)
141+
rexml (3.2.8)
142+
strscan (>= 3.0.9)
143+
ruby-saml (1.16.0)
144+
nokogiri (>= 1.13.10)
145+
rexml
146+
sprockets (4.2.1)
147+
concurrent-ruby (~> 1.0)
148+
rack (>= 2.2.4, < 4)
149+
sprockets-rails (3.4.2)
150+
actionpack (>= 5.2)
151+
activesupport (>= 5.2)
152+
sprockets (>= 3.0.0)
153+
sqlite3 (1.7.3-arm64-darwin)
154+
strscan (3.1.0)
155+
thor (1.3.1)
156+
timeout (0.4.1)
157+
tzinfo (2.0.6)
158+
concurrent-ruby (~> 1.0)
159+
websocket-driver (0.7.6)
160+
websocket-extensions (>= 0.1.0)
161+
websocket-extensions (0.1.5)
162+
zeitwerk (2.6.14)
163+
164+
PLATFORMS
165+
arm64-darwin
166+
167+
DEPENDENCIES
168+
bcrypt (~> 3.1.7)
169+
bootsnap
170+
coco_auth!
171+
sqlite3 (~> 1.4)
172+
173+
BUNDLED WITH
174+
2.5.9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# frozen_string_literal: true
2+
3+
require_dependency 'coco_auth/application_controller'
4+
5+
module CocoAuth
6+
module Admin
7+
class AppsController < ApplicationController
8+
def index
9+
@apps = App.all
10+
end
11+
12+
def new
13+
@app = App.new
14+
end
15+
16+
def create
17+
@app = App.new(app_params)
18+
if @app.save
19+
redirect_to admin_apps_path
20+
else
21+
render :new
22+
end
23+
end
24+
25+
private
26+
27+
def app_params
28+
params.require(:app).permit(:name, :description, :entity_id, :assertion_consumer_service_url, :sso_url,
29+
:slo_url, :certificate)
30+
end
31+
end
32+
end
33+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# frozen_string_literal: true
2+
3+
require_dependency 'coco_auth/application_controller'
4+
5+
module CocoAuth
6+
module Admin
7+
class UsersController < ApplicationController
8+
def index
9+
@users = User.all
10+
end
11+
12+
def new
13+
@user = User.new
14+
end
15+
16+
def create
17+
@user = User.new(user_params)
18+
if @user.save
19+
redirect_to admin_users_path
20+
else
21+
render :new
22+
end
23+
end
24+
25+
private
26+
27+
def user_params
28+
params.require(:user).permit(:email, :password, :password_confirmation, :first_name, :last_name)
29+
end
30+
end
31+
end
32+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
3+
module CocoAuth
4+
class SamlController < ApplicationController
5+
skip_before_action :verify_authenticity_token, only: [:acs]
6+
7+
def auth
8+
settings = SamlSettings.get_saml_settings
9+
request = OneLogin::RubySaml::Authrequest.new
10+
redirect_to(request.create(settings))
11+
end
12+
13+
def acs
14+
settings = SamlSettings.get_saml_settings
15+
response = OneLogin::RubySaml::Response.new(params[:SAMLResponse], settings:)
16+
17+
if response.is_valid?
18+
user = User.find_by(email: response.name_id)
19+
sign_in(user)
20+
redirect_to main_app.root_url
21+
else
22+
render plain: 'Invalid SAML Response'
23+
end
24+
end
25+
end
26+
end

app/models/coco_auth/app.rb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
module CocoAuth
4+
class App < ApplicationRecord
5+
validates :name, presence: true
6+
validates :entity_id, presence: true, uniqueness: true
7+
validates :assertion_consumer_service_url, presence: true
8+
validates :sso_url, presence: true
9+
validates :certificate, presence: true
10+
end
11+
end
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module CocoAuth
2-
class ApplicationRecord < ActiveRecord::Base
2+
class ApplicationRecord < ::ActiveRecord::Base
33
self.abstract_class = true
44
end
55
end

app/models/coco_auth/user.rb

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
module CocoAuth
4+
class User < ApplicationRecord
5+
has_secure_password
6+
7+
validates :email, presence: true, uniqueness: true
8+
end
9+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<h1>Apps</h1>
2+
<%= link_to 'New App', new_admin_app_path %>
3+
<ul>
4+
<% @apps.each do |app| %>
5+
<li><%= app.name %></li>
6+
<% end %>
7+
</ul>
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<%= form_with(model: [:admin, @app], local: true) do |form| %>
2+
<% if @app.errors.any? %>
3+
<div id="error_explanation">
4+
<h2><%= pluralize(@app.errors.count, "error") %> prohibited this app from being saved:</h2>
5+
6+
<ul>
7+
<% @app.errors.full_messages.each do |message| %>
8+
<li><%= message %></li>
9+
<% end %>
10+
</ul>
11+
</div>
12+
<% end %>
13+
14+
<div class="field">
15+
<%= form.label :name %>
16+
<%= form.text_field :name %>
17+
</div>
18+
19+
<div class="field">
20+
<%= form.label :description %>
21+
<%= form.text_area :description %>
22+
</div>
23+
24+
<div class="field">
25+
<%= form.label :entity_id %>
26+
<%= form.text_field :entity_id %>
27+
</div>
28+
29+
<div class="field">
30+
<%= form.label :assertion_consumer_service_url %>
31+
<%= form.text_field :assertion_consumer_service_url %>
32+
</div>
33+
34+
<div class="field">
35+
<%= form.label :sso_url %>
36+
<%= form.text_field :sso_url %>
37+
</div>
38+
39+
<div class="field">
40+
<%= form.label :slo_url %>
41+
<%= form.text_field :slo_url %>
42+
</div>
43+
44+
<div class="field">
45+
<%= form.label :certificate %>
46+
<%= form.text_area :certificate %>
47+
</div>
48+
49+
<div class="actions">
50+
<%= form.submit %>
51+
</div>
52+
<% end %>
53+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<h1>Users</h1>
2+
<%= link_to 'New User', new_admin_user_path %>
3+
<ul>
4+
<% @users.each do |user| %>
5+
<li><%= user.email %></li>
6+
<% end %>
7+
</ul>
8+

0 commit comments

Comments
 (0)