Derive every mounted path from ActiveAdmin's namespace - #17
Open
senid231 wants to merge 1 commit into
Open
Conversation
senid231
force-pushed
the
fix-after-sign-in-path
branch
from
August 25, 2026 11:09
44defde to
f95a7e2
Compare
There was a problem hiding this comment.
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 fromActiveAdmin.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_prefixas 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.
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
force-pushed
the
fix-after-sign-in-path
branch
from
August 25, 2026 14:47
f95a7e2 to
08c1c26
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The gem hardcoded
/adminfor 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 fromActiveAdmin.application.default_namespaceinstead, 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/callbackwhile the middleware redirected to/admin/auth/oidc/callback. Drive them separately:path_prefix:goes to the strategy directly (honoured overOmniAuth.config.path_prefix, which Devise owns), andomniauth_route_prefix-- defaulting toomniauth_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 noafter_initializehook 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.