aurelia-open-id-connect
aurelia-open-id-connect copied to clipboard
I need the hashbang to work pushState = false
About 6 months ago I created a proto of Identity Server 3 with AspNet Identity and an Aurelia app. Also with the suggested pushState = true for the Aurelia router. At the time was told to shelve the proto but, was working great. Fast-forward to 6+ months of Aurelia development and now dusting off the proto for OIDC. We now have many items using the hashbang, google tag manager and a WordPress homepage to name a few. So, everything works until I set pushState = true. I've tried many different configs with the redirect urls without any luck. I do not know how to create a hack to make this work or even where to start.
Any ideas would be very helpful.
I have the open-id-connect-configuration
export const oidcConfig = {
loginRedirectModuleId: 'home',
logoutRedirectModuleId: 'home',
userManagerSettings: {
post_logout_redirect_uri: `${environment.openidConfig.urls.host}/#/signout-oidc`,
redirect_uri: `${environment.openidConfig.urls.host}/#/signin-oidc`,
}
app.js
config.options.pushState = false;
I can get the IdSvr login and authenticate but redirecting to the aurelia app I get the following...
deep-extend.ts:148 ERROR [app-router] TypeError: Cannot set property 'route' of undefined
at http://localhost:9000/scripts/vendor-bundle.js:47048:17
From previous event:
at AppRouter._createRouteConfig (http://localhost:9000/scripts/vendor-bundle.js:47047:10)
at catchAllHandler (http://localhost:9000/scripts/vendor-bundle.js:46939:23)
at evaluateNavigationStrategy (http://localhost:9000/scripts/vendor-bundle.js:47085:38)
at AppRouter._createNavigationInstruction (http://localhost:9000/scripts/vendor-bundle.js:47028:16)
at AppRouter.loadUrl (http://localhost:9000/scripts/vendor-bundle.js:47626:19)
at BrowserHistory._loadUrl (http://localhost:9000/scripts/vendor-bundle.js:42881:55)
at BrowserHistory.activate (http://localhost:9000/scripts/vendor-bundle.js:42780:21)
at AppRouter.activate (http://localhost:9000/scripts/vendor-bundle.js:47681:20)
at http://localhost:9000/scripts/vendor-bundle.js:47652:31
at
I think that we can't use # simbols on the redirect urls because the identity server is using fragements to send tokens states etc. something ${callbackUrl}#token=(...) and so token will mess with routing match.
I solved this be using a callback.html page that redirects back to '/' after. Not sure if is a good soluction but seems like the aurelia-router is not able to detect redicted to routes because fragments are used to send values in the redirect url.
Maybe instead of register redirect_uri as a aurelia router, it should be handled by a different mechanism just for these urls
Please can you share your callback.html? What do I have to do in callback.html besides the redirect?
is a regular html. with a body like this
was doing the job a few version ago, not sure about now.
Thanks! It works!
You can also handle authentication yourself in aurelia's configure method (by default located in main.ts). in one of my projects:
async function configure() {
.......
await aurelia.start();
// this code runs before the aurelia-router kicks in
if (window.location.hash.indexOf("#id_token") > -1) {
let openIdConnect = aurelia.container.get(OpenIdConnect) as OpenIdConnect;
let isSilentLogin = window.top !== window.self;
if (isSilentLogin) {
await openIdConnect.userManager.signinSilentCallback();
} else {
await openIdConnect.userManager.signinRedirectCallback();
}
}
aurelia.setRoot(PLATFORM.moduleName("app"));
}
I'll see if we can get this baked in, or at least documented