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

Route "/signin-oidc" don't found in production #52

Closed dro-sh closed 4 years ago

dro-sh commented 6 years ago

I have my own idsr app, that works fine and it is published on my IIS server (maybe it dont good idea, but thus I can check how it will work in production). Also I have my au-app based on AspNetCore.SpaTemplates. But after webpack 4 was released, I modernized this template to work with webpack 4. I spend a lot of time to do this but point was reached. After that I connected and set up aurelia-open-id-connect plugin. In debug all works fine. User can authorize and app can do request to API . But I decided to check how it will work after publish also on my IIS server. And I have one problem:

  1. User click button login.
  2. User is redirected to idsr app (app.com/Name/account).
  3. User login there.
  4. User is redirected back (app.com/Name/au-app/Name/au-app/signin-oidc).
  5. Aurelia-router can't found route (/Name/au-app/signin-oidc). issue Is my oidc plugin config wrong? Is it problem with pushState on IIS (without oidc-plugin routing works fine)? Also I had tried it with your example (https://github.com/aurelia-contrib/aurelia-open-id-connect-demos/tree/master/aurelia-app-aspnet-core) but got the same after publishing. In debug all works fine. issue-ex
Alexander-Taran commented 6 years ago

asked for collective mind help here: https://discourse.aurelia.io/t/challenge-2-help-a-fellow-developer/915

gerbendekker commented 6 years ago

mmm, All I can tell now that ASP.NET+webpack 3.3+Aurelia OIDC works on my machine using a integrated authority. That means this plugin with pushState works on IIS.

afbeelding

gerbendekker commented 6 years ago

Also you refer to the demo project, I tested this one also. (Ps the link is not working in your description) This is a http app combined with https://demo.identityserver.io as authority and working in IIS on my machine.

afbeelding

dro-sh commented 6 years ago

@gerbendekker I published this template combined with https://demo.identityserver.io as authority. But got the same. http://drogserj.ddns.net/Nugas/pref (sorry for http)

gerbendekker commented 6 years ago

I think its a bug where the routes are created by this plugin. Look at the differences when compare the href /fetch-data vs relativeHref /Nugas/pref/signin-oidc @shaunluttin /Nugas/pref/signin-oidc should be /signin-oidc here.

afbeelding

dro-sh commented 6 years ago

@gerbendekker maybe it don't work because I configured routerConfig.options.root = "/Nugas/pref"; ? It is necessary for PushState.

dro-sh commented 6 years ago

I think I found reason. Method getPath return pathname of anchor, which have /Nugas/pref/signin-oidc value.

default 1

dro-sh commented 6 years ago

I propose next solution. Aurelia's pushState requeres to set routerConfiguration.options.root, which value indicates to tag base. Therefore tag base will always included and it's baseURI will correspond to site URL.

           OpenIdConnectRouting.prototype.getPath = function (uri) {
            + var anchor = this.convertUriToAnchor(uri);
            + var siteUrl= document.getElementsByTagName("base")[0].baseURI;
            + return anchor.href.replace(siteUrl, "");
           };

Is's all changes. What do you think?

shaunluttin commented 6 years ago

Thank you for looking in to this. I appreciate it.

sreddim commented 6 years ago

Hi, I had the similiar problem with system js and webpack when published on IIS

This is because it is trying to read static files.

Use url rewrite to set the redirect paths.

If you have Url rewrite module installed then add this web.config file in the root level of application on production.

If not first install Url rewrite module from microsoft and then add this web.config file. Once you add the web.config as shown below, the Urlrewrite will pick up the rules set up from the web.config and wont look for static files.

<configuration>
    <system.webServer>
 <!--  this is needed when iis is unable to read json files because of mime type missing -->
<!-- <staticContent>
            <mimeMap fileExtension=".json" mimeType="application/json" />
        </staticContent>   -->
   <rewrite>
             <rules>
                 <remove name="redirect all requests" />
                 <rule name="redirect all requests" stopProcessing="true">
                     <match url="^(.*)$" ignoreCase="false" />
                     <conditions logicalGrouping="MatchAll">
                         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />  
             <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />        
                     </conditions>
                     <action type="Rewrite" url="/" appendQueryString="true" />
                 </rule>
             </rules>
         </rewrite> 
    </system.webServer>
</configuration>

Hope this helps.

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!

dro-sh commented 4 years ago

I don't use it. So I can't say does it work.