Altinn / app-frontend-react

Altinn application React frontend
BSD 3-Clause "New" or "Revised" License
18 stars 31 forks source link

New instance is created when unauthenticated user accesses instance via direct link #801

Open acn-sbuad opened 3 years ago

acn-sbuad commented 3 years ago

Describe the bug

If a user bookmarks an instance, and goes directly to this link to work on the form withough being logged in, a new instance is created, rather than the user having to authenticate themselves and then being returned to the existing instance.

To Reproduce

Steps to reproduce the behavior:

  1. Go to https://ttd.apps.tt02.altinn.no/ttd/apps-test
  2. Log on and start filling out form
  3. Save url
  4. Log out of altinn
  5. Access url directly
  6. Log on with same test user
  7. See error

Expected behavior

User has to log in and is then redirected to the initial instance.

Analysis

When pasting direct url in browser e.g. http://altinn3local.no/ttd/apps-test/#/instance/512345/3b11f912-1a00-478e-bf77-df4ae6f615f2 The request found in the network log is: http://altinn3local.no/ttd/apps-test/

We need to reconsider the route to the endpoint that returns the frontend view. Changing # for display or another string fixes the problem, so we need a character that is forwarded by the browser to the server. # is not a valid character.

Alternatively, browser-routes could be used by app frontend instead.

note that redirect url in backend should be defined as

    string goToUrl = HttpUtility.UrlEncode($"{scheme}://{Request.Host}{Request.Path}");

including query parameters could also be considered here.

Browser router instead of hash-router

The issue has come from the fact that we use hash-router as the routing tool in our SPA. An option here would instead be to use browser-router which actually uses the HTML5 history API (pushState, replaceState and the popstate event) to keep your UI in sync with the URL. This would solve the issue of having the full url in backend when doing the redirect.

Some questions that do arise:

Tasks

acn-sbuad commented 3 years ago

Analysis shows that this cannot be solved by a change in backend alone. Adding the frontend label

TheTechArch commented 3 years ago

My suggested solution

  1. Disable authentication on backend for home controller
  2. See of current frontendcode already will work (perform redirects for authentication)
  3. Updated frontend to redirect user for authentication
FinnurO commented 2 years ago

Related to https://github.com/Altinn/app-frontend-react/issues/344