【发布时间】:2017-07-15 15:00:22
【问题描述】:
我正在尝试将 ui-router-ng2 与 Auth0(身份验证即服务提供商)一起使用。问题是登录后 Auth0 将用户重定向到如下所示的 url:
http://localhost:3000/#access_token=alCUyTW2WKLkV8Fq&{etc...}
我已尝试更改该重定向 url,使其命中组件,但使用 auth0 似乎不可能。
使用 ui-router 1,可以添加 http 拦截来处理此问题,但此时 angular 2 中没有 http 拦截功能。
当使用 auth0 和 angular 2 默认路由器时,重定向的处理方式如下:
this
.router
.events
.filter(event => event.constructor.name === 'NavigationStart')
.filter(event => (/access_token|id_token|error/).test(event.url))
.subscribe(() => {
this.lock.resumeAuth(window.location.hash, (error, authResult) => {
if (error) return console.log(error);
localStorage.setItem('id_token', authResult.idToken);
this.router.navigate(['/']);
});
我浏览了 ui-router-ng2 文档,但没有找到类似的方法。
有什么想法吗?
【问题讨论】:
标签: angular angular-ui-router auth0