1

我正在使用外部身份服务器构建应用程序。登录工作正常,只有当被发送回 signin-oidc 页面时才会发生奇怪的事情。

我正在使用 HashLocationStrategy 所以 URL 看起来像这样。

http://localhost:4200/#/signin-oidc#id_token=....

但是在加载此页面几秒钟后,似乎 URL 在第一个 # 之后被编码,这使得它看起来像这样:

http://localhost:4200/#%2Fsignin-oidc%23id_token=....

这会导致我的应用重定向到 404 页面。

登录重定向回调函数如下所示:

this.manager.signinRedirectCallback().then((user: User) => {
    if (user) {
        this.user = user;
        this.router.navigate(['/']);
    }
});

它没有达到路由器导航功能,所以这不是问题。有人可以帮我解决这个问题吗?

4

2 回答 2

0

您可以尝试反序列化 URL 参数 OnInit

例如:

decodeURIComponent(string)

检索解码的 URL 后调用您的 signinRedirectCallback()

于 2019-12-18T16:06:02.670 回答
0

oidc-client 尝试始终在重定向 url 中找到最后一个哈希分隔符,将您的redirect_uri更改为:

redirect_uri: 'http://localhost:4200/#/auth-callback#',

我建议您为此添加一个处理程序组件

{ path: 'auth-callback', component: HandlerComponent },

有内容

export class HandlerComponent implements OnInit {

constructor(private authService: AuthService, private route: Router) {}
ngOnInit() {
  this.authService.completeAuthentication().then((args) => {
    this.route.navigate(['/home']);
  });
 }
}

和服务

completeAuthentication(): Promise<void> {
 return this._userManager.signinRedirectCallback().then((user) => {
    this._user = user; // get the new user
 });
}
于 2019-12-18T16:02:55.850 回答