Skip to content

Derive every mounted path from ActiveAdmin's namespace - #17

Open
senid231 wants to merge 1 commit into
activeadmin-plugins:mainfrom
senid231:fix-after-sign-in-path
Open

Derive every mounted path from ActiveAdmin's namespace#17
senid231 wants to merge 1 commit into
activeadmin-plugins:mainfrom
senid231:fix-after-sign-in-path

Conversation

@senid231

Copy link
Copy Markdown
Member

The gem hardcoded /admin for the post-sign-in landing page, the SSO login/logout routes and the OmniAuth prefix. A host that renames the namespace (config.default_namespace = :backoffice) has no /admin anywhere, so each of those either 404'd or raised. Derive them from ActiveAdmin.application.default_namespace instead, and resolve the post-sign-in path through ActiveAdmin's own root helper on whichever route set holds the host's Devise mapping.

Engine-mounted hosts need one more distinction. Devise reuses a single setting, Devise.omniauth_path_prefix, both to declare its OmniAuth routes and to tell the middleware where to listen; for an engine mounted at a prefix those are different strings, so one value put the callback route at /admin/admin/auth/oidc/callback while the middleware redirected to /admin/auth/oidc/callback. Drive them separately: path_prefix: goes to the strategy directly (honoured over OmniAuth.config.path_prefix, which Devise owns), and omniauth_route_prefix -- defaulting to omniauth_path_prefix, so main-app hosts see no change -- feeds Devise's global. Registering the strategy after the host's config/initializers makes the namespace readable there, so no after_initialize hook or Rails 8 lazy-route workaround is needed.

Covered by unit specs for the namespace derivation and a full OmniAuth round trip against spec/dummy_isolated.

@senid231
senid231 requested review from Fivell and a lite review from Copilot August 25, 2026 11:08
@senid231 senid231 self-assigned this Aug 25, 2026
@senid231
senid231 force-pushed the fix-after-sign-in-path branch from 44defde to f95a7e2 Compare August 25, 2026 11:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes hardcoded /admin assumptions by deriving login/logout/OmniAuth paths (and the post-sign-in landing path) from ActiveAdmin’s configured namespace, with special handling for engine-mounted hosts where Devise’s OmniAuth route prefix and the middleware listening prefix must differ.

Changes:

  • Derive login_path, logout_path, and OmniAuth prefixes from ActiveAdmin.application.default_namespace, while preserving explicit overrides.
  • Split OmniAuth configuration into a per-strategy middleware path_prefix: and a Devise route declaration prefix (omniauth_route_prefix) to support mounted engines correctly.
  • Add/adjust request + isolated-engine specs and update docs/templates to use ActiveAdmin::Oidc.config.omniauth_path_prefix as the source of truth for browser-visible OmniAuth request paths.

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
spec/unit/configuration_spec.rb Adds unit coverage for namespace-derived paths and fallback behavior.
spec/requests/login_path_helper_spec.rb Updates regression spec to assert login view uses configured OmniAuth prefix (not hardcoded).
spec/requests/disabled_user_persistence_spec.rb Switches callback posting to configured OmniAuth prefix.
spec/requests/after_sign_in_path_spec.rb Adds specs for post-sign-in landing path resolution via ActiveAdmin root helper.
spec/isolated/requests/isolated_engine_callback_spec.rb Adds full round-trip coverage for isolated engine mounts with split prefixes.
spec/dummy_isolated/config/initializers/activeadmin_oidc.rb Configures isolated dummy to override omniauth_route_prefix engine-relatively.
README.md Documents namespace derivation and the new omniauth_route_prefix behavior for engines.
Rakefile Minor task definition syntax update for spec:all.
lib/generators/active_admin/oidc/install/templates/sessions_new.html.erb Uses gem config for OmniAuth request path in generated view.
lib/generators/active_admin/oidc/install/templates/sessions_new_v4.html.erb Uses gem config for OmniAuth request path in generated v4 view.
lib/activeadmin/oidc/engine.rb Registers strategy using per-strategy path_prefix: and sets Devise route prefix from config.
lib/activeadmin/oidc/configuration.rb Introduces derived path helpers + omniauth_route_prefix with fallback namespace behavior.
app/views/active_admin/devise/sessions/new.html.erb Uses gem config for OmniAuth request path instead of OmniAuth global.
app/controllers/active_admin/oidc/devise/omniauth_callbacks_controller.rb Redirects post-sign-in via ActiveAdmin’s root helper; adds route-set dispatch helper.
.rspec Updates guidance comment about running spec suites.
.gitignore Adds ignore entries and db.yml exception for new dummy app paths.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread app/controllers/active_admin/oidc/devise/omniauth_callbacks_controller.rb Outdated
The gem hardcoded `/admin` for the post-sign-in landing page, the SSO
login/logout routes and the OmniAuth prefix. A host that renames the
namespace (`config.default_namespace = :backoffice`) has no /admin
anywhere, so each of those either 404'd or raised. Derive them from
`ActiveAdmin.application.default_namespace` instead, and resolve the
post-sign-in path through ActiveAdmin's own root helper on whichever
route set holds the host's Devise mapping.

Engine-mounted hosts need one more distinction. Devise reuses a single
setting, `Devise.omniauth_path_prefix`, both to declare its OmniAuth
routes and to tell the middleware where to listen; for an engine
mounted at a prefix those are different strings, so one value put the
callback route at `/admin/admin/auth/oidc/callback` while the
middleware redirected to `/admin/auth/oidc/callback`. Drive them
separately: `path_prefix:` goes to the strategy directly (honoured over
`OmniAuth.config.path_prefix`, which Devise owns), and
`omniauth_route_prefix` -- defaulting to `omniauth_path_prefix`, so
main-app hosts see no change -- feeds Devise's global. Registering the
strategy after the host's config/initializers makes the namespace
readable there, so no `after_initialize` hook or Rails 8 lazy-route
workaround is needed.

Covered by unit specs for the namespace derivation and a full OmniAuth
round trip against spec/dummy_isolated.

Co-Authored-By: Clanker
@senid231
senid231 force-pushed the fix-after-sign-in-path branch from f95a7e2 to 08c1c26 Compare August 25, 2026 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants