File tree Expand file tree Collapse file tree
app/views/active_admin/devise/sessions Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ < div id ="login ">
2+ < h2 > <%= active_admin_application . site_title ( self ) %> </ h2 >
3+
4+ <%= button_to ActiveAdmin ::Oidc . config . login_button_label ,
5+ "/admin/auth/oidc" ,
6+ method : :post ,
7+ class : "activeadmin-oidc-login-button" ,
8+ data : { turbo : false } %>
9+ </ div >
Original file line number Diff line number Diff line change @@ -40,6 +40,18 @@ def controllers
4040 end
4141 end
4242 end
43+
44+ # Make sure the gem's login view override wins over ActiveAdmin's
45+ # default. ActiveAdmin's view path is registered when its engine
46+ # initializes; we prepend ours in `to_prepare` so it lands in front
47+ # of ActiveAdmin's Devise::SessionsController view lookup.
48+ initializer "activeadmin_oidc.prepend_view_paths" do |app |
49+ app . config . to_prepare do
50+ require "active_admin/devise"
51+ view_path = File . expand_path ( "../../../app/views" , __dir__ )
52+ ::ActiveAdmin ::Devise ::SessionsController . prepend_view_path ( view_path )
53+ end
54+ end
4355 end
4456 end
4557end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ require "rails_helper"
4+
5+ # The gem replaces ActiveAdmin's stock email/password login page with an
6+ # SSO-only button. This spec verifies the view override is picked up
7+ # through the engine's view path and that the button label is sourced
8+ # from configuration.
9+ RSpec . describe "Login page" , type : :request do
10+ before do
11+ ActiveAdmin ::Oidc . configure do |c |
12+ c . issuer = "https://idp.example.com"
13+ c . client_id = "client-abc"
14+ c . on_login = -> ( *) { true }
15+ end
16+ end
17+
18+ it "renders the SSO button with the configured label" do
19+ ActiveAdmin ::Oidc . config . login_button_label = "Sign in with Corporate SSO"
20+
21+ get "/admin/login"
22+
23+ expect ( response ) . to have_http_status ( :ok )
24+ expect ( response . body ) . to include ( "Sign in with Corporate SSO" )
25+ expect ( response . body ) . to include ( %(action="/admin/auth/oidc") )
26+ end
27+
28+ it "does not render email or password fields" do
29+ get "/admin/login"
30+
31+ expect ( response . body ) . not_to match ( /name="admin_user\[ password\] "/ )
32+ expect ( response . body ) . not_to match ( /name="admin_user\[ email\] "/ )
33+ end
34+
35+ it "uses the default login button label when not configured" do
36+ get "/admin/login"
37+
38+ expect ( response . body ) . to include ( ActiveAdmin ::Oidc ::Configuration ::DEFAULT_LOGIN_BUTTON_LABEL )
39+ end
40+ end
You can’t perform that action at this time.
0 commit comments