Skip to content

Commit 4730250

Browse files
committed
Fix Rails 8 lazy route loading breaking OmniAuth path matching
Rails 8 loads routes lazily, so Devise set_omniauth_path_prefix (which runs during route generation) has not fired when OmniAuth middleware processes the first request. The strategy falls back to the default /auth prefix and misses /admin/auth/oidc, returning Devise Authentication passthru 404. Set OmniAuth.config.path_prefix eagerly in the engine initializer after the devise.omniauth call (must be after, because that call triggers autoload of devise/omniauth which nils the value).
1 parent 1496bba commit 4730250

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/activeadmin/oidc/engine.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ def controllers
8787
host: nil
8888
}.compact
8989
end
90+
91+
# Devise propagates omniauth_path_prefix to
92+
# OmniAuth.config.path_prefix during route generation
93+
# (set_omniauth_path_prefix!). On Rails 8 routes load lazily,
94+
# so the OmniAuth middleware may process requests before routes
95+
# are drawn and miss the prefix. Set it eagerly here.
96+
# Must happen AFTER `devise.omniauth` because that call
97+
# triggers autoload of devise/omniauth which nils the value.
98+
::OmniAuth.config.path_prefix = ::Devise.omniauth_path_prefix
9099
end
91100

92101
initializer 'activeadmin_oidc.filter_parameters' do |app|

0 commit comments

Comments
 (0)