在angular2路由器中处理带.html扩展名的网址?

时间:2017-08-07 12:51:40

标签: oauth salesforce angular2-routing

我们正在开发一个Angular2(由angular-cli v1.0.0-beta.28.3创建),它通过OAth的用户代理流机制(https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_user_agent_oauth_flow.htm)连接到Salesforce。

Here是我在代码中使用的验证码。 以下是验证后处理回调的代码:

import { Component } from '@angular/core';
import { ForceService } from './force';

@Component({
  template : ` `,
})
export class AuthComponent {

  constructor(force : ForceService) { 
     var event = new CustomEvent("oauthCallback", {'detail': window.location.href});
     window.opener.document.dispatchEvent(event); 
     window.close();   
  }
}

在Salesforce中,我们有一个名为Connected-App的东西,我们在其中配置用于身份验证的回调URL。回调网址如下所示: 的 https://my.site.com/#/auth-callback 即可。 Angular2路由器配置也使用 useHash:true 选项。

一切正常,直到新要求只需要回调网址指向这样的内容: https://my.site.com/auth-callback.html

所以上面的等效html代码将是:

<html>
    <script type="text/javascript">
    var event = new CustomEvent("oauthCallback", {'detail': window.location.href});
        window.opener.document.dispatchEvent(event); 
        window.close();   
    }
    </script>
</html>

问题,我们面临的是在身份验证之后,我们无法从网址访问access_token并关闭身份验证窗口,因为路由未正确重定向到auth-callback.html。我们得到的只是一个空白屏幕,其网址已更改为 http://localhost:4200/#/access_token

是否可以在不关闭 useHash 的情况下解决此问题?

0 个答案:

没有答案