Skip to content

[dtq-dev-93] Return to the right page after login (DiscoJuice local and Shibboleth, expired session) - #1764

Open
milanmajchrak wants to merge 10 commits into
dtq-dev-93from
93/fe-login-return-redirect
Open

milanmajchrak wants to merge 10 commits into
dtq-dev-93from
93/fe-login-return-redirect

Conversation

@milanmajchrak

@milanmajchrak milanmajchrak commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

References

Ports this dtq-dev PR:

Description

After local or Shibboleth login through DiscoJuice, the user lands on the protected page that sent them to login. A local login started on /login itself ends on the home page, and an expired session opens the login page under the base href.

Instructions for Reviewers

List of changes in this PR:

  • LoginPageComponent puts the stored post-login URL (set by the auth guard) into the URL, e.g. /login?redirectUrl=%2Fmydspace. It does this only in the browser, only when the URL has no redirectUrl yet, and it replaces the history entry. A stored URL with a request-a-copy accessToken is not copied there; it stays in the store, and the password login on /login still returns to it. aai.js takes the return page only from the URL, so before, local and Shibboleth login both returned to /login itself. The v9 port had only the read side in LogInPasswordComponent.submit(); on 7.6 this part lived in LogInPasswordComponent.setUpRedirectUrl().
  • LogInPasswordComponent also strips the base href from redirectUrl (Location.normalize, empty path = /). A login started on /login now targets /login, and AuthService.navigateToRedirectUrl already sends that home. Before, the user ended on "You're Already Logged In".
  • aai.js local login encodes the page URL it puts into /login?redirectUrl=. So the page's query string survives, e.g. /mydspace?configuration=workflow.
  • aai.js Shibboleth login keeps a full URL of this site from redirectUrl (local login puts one there). Before, it put the namespace in front of it. Anything else is still taken as a path in the app.
  • aai.js Shibboleth login encodes the whole backend target, not only the redirectUrl inside it. So /search?query=corpus&page=2 reaches the backend with page=2. Simple return URLs reach the backend unchanged.
  • AuthService.redirectToLoginWhenTokenExpired() goes to ./login?expired=true, relative to <base href> like the reload/ URL. Before, /login?expired=true was a 404 under /repository/. The SSR override in ServerAuthService adds ui.nameSpace to its 302 for the same reason.
  • angular.json no longer copies src/aai/*.spec.ts into the build.
  • Each fix has a spec that fails without it. The new src/aai/aai.spec.ts tests three small aai.js helpers, exposed on window.aai for that.

How to test (UI under /repository/):

  1. Log out. Open <ui>/mydspace. You land on /login?redirectUrl=%2Fmydspace.
  2. In DiscoJuice pick "Local authentication" and log in. You land on /mydspace.
  3. Log out. Open /mydspace again and pick your IdP in DiscoJuice. After the IdP you land on /mydspace. Under /repository/ this also needs the backend auth cookie path fix (backend PR 1490).
  4. Log out. Open <ui>/login directly, pick "Local authentication" and log in. You land on the home page.
  5. Log out. Open <ui>/mydspace?configuration=workflow and log in with "Local authentication". You land on the same URL.
  • npm run test -- --include=<spec> for src/aai/aai.spec.ts, src/app/login-page/login-page.component.spec.ts, src/app/shared/log-in/methods/password/log-in-password.component.spec.ts, src/app/core/auth/auth.service.spec.ts and src/app/core/auth/server-auth.service.spec.ts.

Codex review (gpt-6.2-sol, high), 2 rounds: 2 findings fixed (the Shibboleth target was not encoded as a whole, a stored URL with an accessToken went into the login URL). Not changed in this PR:

  • If ui.nameSpace equals a route prefix, e.g. /items, a return to /items/items/123 loses one /items.
  • A stored URL with a share_token still goes into the login URL, as on 7.x.
  • After a stored download URL with an accessToken, the DiscoJuice "Local authentication" login ends on the home page.

Checklist

  • My PR is created against the main branch of code (unless it is a backport or is fixing an issue specific to an older branch).
  • My PR is small in size (e.g. less than 1,000 lines of code, not including comments & specs/tests), or I have provided reasons as to why that's not possible.
  • My PR passes ESLint validation using npm run lint
  • My PR doesn't introduce circular dependencies (verified via npm run check-circ-deps)
  • My PR includes TypeDoc comments for all new (or modified) public methods and classes. It also includes TypeDoc for large or complex private methods.
  • My PR passes all specs/tests and includes new/updated specs or tests based on the Code Testing Guide.
  • My PR aligns with Accessibility guidelines if it makes changes to the user interface.
  • My PR uses i18n (internationalization) keys instead of hardcoded English text, to allow for translations.
  • My PR includes details on how to test it. I've provided clear instructions to reviewers on how to successfully test this fix or feature.
  • If my PR includes new libraries/dependencies (in package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.
  • If my PR includes new features or configurations, I've provided basic technical documentation in the PR itself.
  • If my PR fixes an issue ticket, I've linked them together.

🤖 Generated with Claude Code

milanmajchrak and others added 10 commits November 26, 2026 14:43
The login page puts the stored post-login target into ?redirectUrl=, so aai.js
keeps it through the local-login reload and in the Shibboleth target.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A password login started on the login page itself now ends on the home page, as in 7.x, instead of on the already-logged-in message.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
aai.js now encodes the return URL it puts into /login?redirectUrl=, so a query string like ?configuration=workflow or a second param survives the reload.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The hard redirect used /login?expired=true, which drops the base href and gives a 404 when the UI runs under a sub-path like /repository/.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
After local login the login page has a full URL in redirectUrl. aai.js put the namespace in front of it, so Shibboleth returned to a broken URL.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Location.normalize turns the home page URL into an empty string, so a stored page won over it. An empty path now means /.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The server answered with a 302 to /login?expired=true, which the browser resolves from the host root, not from the base href.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Only the inner redirectUrl was encoded, so a return page like /search?query=corpus&page=2 reached the backend without page=2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A request-a-copy return URL with accessToken stays in the store only; the password login on the login page still returns to it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

1 participant