Skip to content

Commit 6be4c22

Browse files
committed
feat(oidc_only): can show only oidc login
1 parent 39adbba commit 6be4c22

10 files changed

Lines changed: 89 additions & 11 deletions

File tree

app/assets/stylesheets/application.scss

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,4 +1047,12 @@ td.day .calendar-text {
10471047
top: 0;
10481048
}
10491049
}
1050-
}
1050+
}
1051+
1052+
.btn-oidc-only {
1053+
font-size: 36px;
1054+
padding: 4px;
1055+
margin: 12px 10px;
1056+
display: flex;
1057+
justify-content: center;
1058+
}

app/helpers/application_helper.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,4 +698,14 @@ def unverified_notice(resource)
698698
def theme_path
699699
"themes/#{params[:theme_preview] || current_space&.theme || TeSS::Config.site['default_theme'] || 'default'}"
700700
end
701+
702+
def omniauth_login_link(provider, config)
703+
link_to(
704+
t('authentication.omniauth.log_in_with',
705+
provider: config.options[:label] ||
706+
t("authentication.omniauth.providers.#{provider}", default: provider.to_s.titleize)),
707+
omniauth_authorize_path('user', provider),
708+
method: :post
709+
)
710+
end
701711
end

app/models/user.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ class User < ApplicationRecord
6262
before_save :set_username_for_invitee
6363

6464
# Include default devise modules. Others available are: :lockable, :timeoutable
65-
if TeSS::Config.feature['registration']
65+
if TeSS::Config.feature['login_through_oidc_only']
66+
devise :database_authenticatable, :confirmable, :trackable, :validatable, :omniauthable, :authentication_keys => [:login]
67+
elsif TeSS::Config.feature['registration']
6668
devise :database_authenticatable, :confirmable, :registerable, :invitable, :recoverable, :rememberable, :trackable,
6769
:validatable, :omniauthable, :authentication_keys => [:login]
6870
elsif TeSS::Config.feature['invitation']

app/views/devise/sessions/_omniauth_options.html.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<% if devise_mapping.omniauthable? -%>
22
<% Devise.omniauth_configs.each do |provider, config| -%>
33
<%= link_to(omniauth_authorize_path(resource_name, provider), method: :post,
4-
class: config.options[:logo] ? '' : 'btn btn-default') do %>
4+
class: config.options[:logo] ? '' :
5+
TeSS::Config.feature["login_through_oidc_only"] ? 'btn btn-default btn-lg btn-oidc-only' : 'btn btn-default') do %>
56
<% if config.options[:logo].present? %>
67
<%= image_tag(config.options[:logo], class: "omniauth-logo omniauth-#{provider}") -%>
78
<% else %>

app/views/devise/sessions/new.html.erb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<div class="account-form">
22
<div class="page-header">
3+
<% if !TeSS::Config.feature["login_through_oidc_only"] %>
34
<%= page_title 'Log in' %>
5+
<% end %>
46
</div>
57
<div class="form-middle">
68
<% if resource_class.omniauth_providers.any? && devise_mapping.omniauthable? %>
@@ -10,19 +12,33 @@
1012
<hr/>
1113
<% end %>
1214

15+
<% if TeSS::Config.feature["login_through_oidc_only"] %>
16+
<dl class="faq">
17+
<div class="question">
18+
<dt>
19+
<h4><div class="expand">+</div><%= t('authentication.omniauth.admin') %></h4>
20+
</dt>
21+
<dd style="display: none;">
22+
<% end %>
1323
<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
1424
<div class="h4"><%= t('authentication.password.title') %></div>
1525
<p><%= t('authentication.password.description') %></p>
1626
<%= f.input :login, label: t('authentication.password.email_or_username'), autofocus: true %>
1727
<%= f.input :password, label: t('authentication.password.password'),
18-
input_html: { autocomplete: 'off' } %>
28+
input_html: { autocomplete: 'off' } %>
1929
<% if devise_mapping.rememberable? -%>
2030
<%= f.input :remember_me, label: t('authentication.password.remember_me'), as: :boolean %>
2131
<% end -%>
2232
<div class="actions">
2333
<%= f.submit t('authentication.password.log_in'), :class => 'btn btn-primary' %>
2434
</div>
2535
<% end %>
36+
<% if !TeSS::Config.feature["login_through_oidc_only"] %>
2637
<%= render "devise/shared/links" %>
38+
<% else %>
39+
</dd>
40+
</div>
41+
</dl>
42+
<% end %>
2743
</div>
2844
</div>

app/views/layouts/_login_menu.html.erb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
<% if TeSS::Config.feature["login_through_oidc_only"] && Devise.omniauth_configs.size == 1 %>
2+
<li>
3+
<% provider, config = Devise.omniauth_configs.first %>
4+
<%= omniauth_login_link(provider, config) %>
5+
</li>
6+
<% else %>
17
<li class="dropdown">
28
<a class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
39
<strong>Log In</strong> <span class="caret"></span>
410
</a>
511
<ul class="dropdown-menu dropdown-menu-right">
612
<% Devise.omniauth_configs.each do |provider, config| -%>
7-
<li class="dropdown-item">
8-
<%= link_to t('authentication.omniauth.log_in_with',
9-
provider: config.options[:label] || t("authentication.omniauth.providers.#{provider}", default: provider.to_s.titleize)),
10-
omniauth_authorize_path('user', provider), method: :post %>
11-
</li>
13+
<li class="dropdown-item"><%= omniauth_login_link(provider, config) %></li>
1214
<% end %>
1315

1416
<li class="dropdown-item">
@@ -23,3 +25,4 @@
2325
<% end %>
2426
</ul>
2527
</li>
28+
<% end %>

config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ en:
743743
oidc: OpenID Connect
744744
oidc2: Alternative OpenID Connect
745745
log_in_with: 'Log in with %{provider}'
746+
admin: Admin
746747
ingestion:
747748
categories:
748749
events: 'Events'

config/tess.example.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,11 @@ default: &default
147147
feature:
148148
elearning_materials: false
149149
events: true
150-
invitation: false
151150
materials: true
152151
nodes: false
153152
collections: true
154153
content_providers: true
155154
subscription: true
156-
registration: true
157155
trainers: false
158156
workflows: true
159157
sources: false
@@ -171,6 +169,9 @@ default: &default
171169
learning_paths: false
172170
collection_curation: true
173171
spaces: false
172+
invitation: false
173+
registration: false
174+
login_through_oidc_only: false # when true, only the first oidc authentication will be available in TeSS, useful when you have your org SSO. Be careful! invitation and registration must be false when using this feature.
174175
restrict_content_provider_selection: false
175176
user_ingestion_methods: ['bioschemas']
176177
placeholder:

test/controllers/static_controller_test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,4 +493,22 @@ class StaticControllerTest < ActionController::TestCase
493493
end
494494
end
495495
end
496+
497+
test 'should find log in drop down when login_through_oidc_only is disabled' do
498+
with_settings({ feature: { login_through_oidc_only: false } }) do
499+
get :home
500+
assert_select 'ul.user-options.nav.navbar-nav.navbar-right' do
501+
assert_select 'a.dropdown-toggle', count: 1
502+
end
503+
end
504+
end
505+
506+
test 'should find log in button when login_through_oidc_only is enabled' do
507+
with_settings({ feature: { login_through_oidc_only: true } }) do
508+
get :home
509+
assert_select 'ul.user-options.nav.navbar-nav.navbar-right' do
510+
assert_select 'a[href="/users/auth/oidc"]', text: 'Log in', count: 1
511+
end
512+
end
513+
end
496514
end

test/integration/login_test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ class LoginTest < ActionDispatch::IntegrationTest
2929
logout_user
3030
end
3131

32+
test 'should not see big login button and admin login when login_through_oidc_only is disabled' do
33+
with_settings({ feature: { login_through_oidc_only: false } }) do
34+
get '/users/sign_in'
35+
assert_response :success
36+
assert_select 'div.form-middle a.btn-oidc-only', false
37+
assert_select 'dl.faq', false
38+
end
39+
end
40+
41+
test 'should see big login button and admin login when login_through_oidc_only is enabled' do
42+
with_settings({ feature: { login_through_oidc_only: true } }) do
43+
get '/users/sign_in'
44+
assert_response :success
45+
assert_select 'div.form-middle a.btn-oidc-only'
46+
assert_select 'dl.faq'
47+
end
48+
end
49+
3250
private
3351

3452
def login_user(username, identifier, password)

0 commit comments

Comments
 (0)