From uri incorrect after being route guarded (Okta Angular)

I am running into an issue where the uri called after my callback is wrong when i get guarded. After doing some digging it appears that the okta route guard will use the router state snapshot to set the from uri prior to redirecting the user to the login flow. The router state url is a relative path with a slash at the beginning which is causing the from uri to be set as ‘origin + state.url’. This is based on looking at the okta auth service. My app does not live at the origin of our domain and thus when the callback redirects it goes to the wrong uri. Is there something i am doing wrong? Could this be a bug?

What i want after callback redirects: www.app.com/base/list
What happens after callback redirects: www.app.com/list

You might need to build your Angular app with a base-href flag. For example:

ng build --prod --base-href /base

The app is being built with the base href flag. Overall the auth works as intended its just when the user is guarded (hits a path and hasnt been authenticated). I have a temporary work around. I copied the the code from the okta route guard and strip the initial slash from the route that is resolved from the state.url. When i do this the set FromUri function doesnt append the path to the origin and i get properly routed.

Has there been an official solution to this, without modifying Okta code? We are currently running into the same problem. It seems like the OktaAuthGuard is incorrectly setting the URI to return to.

Facing this same issue, would prefer to not have to create a work around for this. Any update?

1 Like