OktaAuthGuard redirects incorrectly

I have an Angular 9 app using the latest Okta Angular npm package. The app is hosted at /app (ie base URL is not /) and has routes protected with OktaAuthGuard.

After the auth happens, the redirect from the callback route (/app/implicit/callback) always goes to /, which of course is the wrong page. However, if I manually go to the correct URL prefixed with /app, everything is good and I am logged in.

How can I make the OktaAuthGuard redirects correctly honor the base href or otherwise work around this?

We are currently having the exact same issue. I haven’t seen a solution posted anywhere.

The solution I came up with was to create a duplicate OktaAuthGuard in my project. You can then inject PlatformLocation and use getBaseHrefFromDOM(). Prepend this to state.url. State.url is relative to the root router URL so it really shouldn’t be used as the URL that gets passed to an external service.

this.oktaAuth.setFromUri(state.url);

Becomes (use whatever pathJoin function suits you):

this.oktaAuth.setFromUri(this.pathJoin([this.baseHref, state.url], '/'));

Angular docs: https://angular.io/api/common/PlatformLocation#getBaseHrefFromDOM

Hopefully the Okta team will come up with an official solution.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.