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

Signin redirect does not work in production. #34

Closed sreddim closed 4 years ago

sreddim commented 6 years ago

Hi, In my application I need to set the signin redirect after the default page is loaded and click on login button from that default page.

This scenario works on debug mode but not in production.

It works in production only if I do it from app.ts in which case I loose the option to choose between register / login. It does not throw any error in production, but it just never redirects and nothing loads in the page.

--app.ts

config.map([

{route: ['', 'login'], name: 'login', settings: { icon: 'home' }, moduleId: PLATFORM.moduleName('./login'), nav: true, title: 'Home'}, {route: 'profile', name: 'profile', settings: { icon: 'education', auth: true}, moduleId: PLATFORM.moduleName('./profile'), nav: true, title: 'Profile'},

]); this.openIdConnect.configure(config); this.config = config; this.router = router;

-->pipeline step: config.addPipelineStep('authorize', AuthorizeStep);

-->run method from AuthorizeStep: async run(navigationInstruction, next) : Promise{

// currently active route config
let currentRoute = navigationInstruction.config;

// settings object will be preserved during navigation
let loginRequired = currentRoute.settings && currentRoute.settings.auth === true;

let user =  await this.openIdConnect.userManager.getUser();
  if (typeof user === undefined || user === null)
      {  
       this.isAuthenticated = false;  
      }
      else
        {
        this.isAuthenticated = true;
        }
if (this.isAuthenticated === false && loginRequired === true) {
  return next.cancel( this.openIdConnect.userManager.signinRedirect());   
}   
return next(this.isAuthenticated);

}

Could please help me to solve this. Tried to move the login page out from app configrouter and in the main.ts set the root to login.

if(app == null || app.user == null) {

aurelia.start().then(() => aurelia.setRoot(PLATFORM.moduleName('login'))); } else {

aurelia.start().then(() => aurelia.setRoot(PLATFORM.moduleName('app'))); }

But this approach loads the login page always and after signin and redirect it loads login page 3 times and clicking login 3 times before it goes to my actual profile page which is added as my login redirect.

const oidcConfig: OpenIdConnectConfiguration = { loginRedirectModuleId: PLATFORM.moduleName("./profile"),

works in debug mode. image

not in production. image

shaunluttin commented 6 years ago

Have you experimented with the demos here?

https://github.com/shaunluttin/aurelia-open-id-connect-demos

If you could please reproduce the issue you're experience in a public fork, that would speed up the troubleshooting that I can provide.

AndreSteenbergen commented 6 years ago

Have you added the client configuration in the server code for production? It might be the case you allowed your debug environment to communicate with the id server, but not the client on production.

sreddim commented 6 years ago

Hi I have client configuration in place. Everything loads in production if I do not have login(Home tab) view included in the app routingconfig and set this as root in main. But the problem is even after login it takes 3 clicks to redirect to to app/profile. That is the reason I used pipeline step and had all my views(including login(Home tab)) in app configrouter but that does not work in production.

shaunluttin commented 6 years ago

There is a chance that protocol switching is the problem. In production, are you using HTTPS for all the pages?

sreddim commented 6 years ago

Hi Shaunluttin , Yes my host, id server, and other api urls everything is using https.

I had the same problem when i published it in local IIS.

I will try to recreate using the demos you have provided.

sreddim commented 6 years ago

Hi, The problem is when I publish it in iis as application it does not load, but if I publish it as a site it is working with all pages in single app router.

I have added web.config with rewrite rule as below to resolve the file not found error for static files. Could this be the reason? or any changes in this would fix it? Appreciate you suggestion on this.

<?xml version="1.0" encoding="UTF-8"?>

**AS APPLICATION** ![image](https://user-images.githubusercontent.com/33684748/33718109-9dd8f130-db5c-11e7-8a8f-a187d9bc3f50.png) **AS SITE** ![image](https://user-images.githubusercontent.com/33684748/33718162-c8afee7c-db5c-11e7-8e22-ef8bdaa38da2.png)
shaunluttin commented 6 years ago

Apologies for not having responded... I have been away from the computer for a while.

arnederuwe commented 4 years ago

Hi, I will be closing up stale issues by the end of the week.

Are you still experiencing this issue? Feel free to close this yourself. If you are still experiencing this issue, let me know as well, thanks!