aurelia-contrib / aurelia-open-id-connect

An aurelia adapter for the IdentityModel/oidc-client-js
https://zamboni-app.azurewebsites.net
MIT License
54 stars 18 forks source link

Feature request: automatic forward to the route with the module of redirect #17

Closed AndreSteenbergen closed 6 years ago

AndreSteenbergen commented 7 years ago

After successful login/ logout, it might be nicer to redirect the user to the module designated in the configuration. Just a nice to have, or is it already possible?

shaunluttin commented 7 years ago

If I recall correctly, this is already possible.

shaunluttin commented 6 years ago

Turns out that this is not already possible but is easy for me to add.

shaunluttin commented 6 years ago

I will add this feature once finishing the unit-tests.

AndreSteenbergen commented 6 years ago

Thanks, a redirect will certainly be more user friendly in the url. Is it also possible to have a redirect parameter as well? I mean, something like usermanager.loginRedirect({redirectAfterLogin: "mysteriousPage?howdidIgethere"}), but I guess that will be harder ...

shaunluttin commented 6 years ago

I looked at this today, and it appears already to be working with this configuration:

export default {
  loginRedirectModuleId: "private",
  logoutRedirectModuleId: "index",
}

https://github.com/shaunluttin/aurelia-open-id-connect-demos has an auth0 demo that does that. Does that properly capture the requirements?

shaunluttin commented 6 years ago

If the above captures the initial requirements, let me know, and I can also consider opening an issue for the redirect parameters(s).

AndreSteenbergen commented 6 years ago

Thanks, will try it tomorrow at work

AndreSteenbergen commented 6 years ago

I am doing that right now, but it sticks with to redirected url with the entire hash. The hash part is what I am trying to avoid, because I have 1 requirement to show as clean urls as possible. That's why I am adding a an url into the history stack, so the hash-fragment is removed from the address bar history.pushState({}, "Welcome back", ""); This feature request was more a "don't load the module, but redirect to the module".

I have the following in my configuration:

export default {
    redirect_route: redirect_route, 
    loginRedirectModuleId : "modules/dashboard",
    logoutRedirectModuleId: "modules/dashboard",
    userManagerSettings : config
};
AndreSteenbergen commented 6 years ago

I guess this does the loading (from the source (open-id-connect-navigation-strategies.ts))

it tells the navigationInstruction which module to load. I would like to perform a redirect instead. That isn't possible at this moment right?

public async signInRedirectCallback(instruction: NavigationInstruction): Promise<any> {
        const callbackHandler = async () => {
            const args: any = {};
            return this.userManager.signinRedirectCallback(args);
        };

        const postCallbackRedirect = () => {
            instruction.config.moduleId =
                this.openIdConnectConfiguration.loginRedirectModuleId;
        };

        return this.runHandlerAndAlwaysRedirect(callbackHandler, postCallbackRedirect);
    }
shaunluttin commented 6 years ago

Hmm. I understand now. You clarified with the "don't load the module, redirect to the module" comment. That makes sense, and I think it runs into the limits of how well I understand Aurelia's router. I'll take a look at how to redirect instead of to load. If you know how to do that, please let me know (or create a PR), and I will implement it ASAP.

AndreSteenbergen commented 6 years ago

I will try and see what I can do, I am probably working on our front end application tomorrow. Don't see why I can't make an extra adjustment, in this bridge.

shaunluttin commented 6 years ago

We played with this for about 30-minutes this afternoon.

This is the original code:

const postCallbackRedirect = () => {
    instruction.config.moduleId =
        this.openIdConnectConfiguration.loginRedirectModuleId;
};

Filling the redirect requirement is as easy as this:

const postCallbackRedirect = () => {
    instruction.config.redirect =
        this.openIdConnectConfiguration.loginRedirectModuleId;
};
shaunluttin commented 6 years ago

Fixed with 11ea315a8ff741c670e1f33cd332a397aa87efbc

shaunluttin commented 6 years ago

Let me know if that change works for you. I prefer the redirect too. Thank you for the suggestion. :-)

AndreSteenbergen commented 6 years ago

The art of time zones ;) Yes that will work, just one method change wow... Have you placed this in the npm package, or should I build from source?

shaunluttin commented 6 years ago

It's in the NPM package. 👍