手动调用signingSilent时oidc-client框架错误

时间:2019-07-08 06:54:36

标签: angular identityserver4 oidc-client-js angular-auth-oidc-client

有点奇怪。在我的Angular应用程序上,我有一个refreshUser方法来在显示所有屏幕数据之前加载可能已登录的用户。为此,我有以下ngOnInit方法:

async ngOnInit() {
    await this.authService.refreshUser();
}

refreshUser方法具有以下代码:

public refreshUser(): Promise<void> {
        return this.manager.signinSilent()
                            .then(user => {
                                this.user = user;
                            })
                            .catch(e => {
                                console.log('User not logged in', e);
                            });
    }

在全新的导航上,它可以顺利运行,并且出现错误:

User not logged in ErrorResponse: login_required
    at new e (main.2a53201b6340bff6258a.js:1)
    at t._processSigninParams (main.2a53201b6340bff6258a.js:1)
    at t.validateSigninResponse (main.2a53201b6340bff6258a.js:1)
    at main.2a53201b6340bff6258a.js:1
    at e.invoke (polyfills.3efb6da5a4e032fb1cf9.js:1)
    at Object.onInvoke (main.2a53201b6340bff6258a.js:1)
    at e.invoke (polyfills.3efb6da5a4e032fb1cf9.js:1)
    at t.run (polyfills.3efb6da5a4e032fb1cf9.js:1)
    at polyfills.3efb6da5a4e032fb1cf9.js:1
    at e.invokeTask (polyfills.3efb6da5a4e032fb1cf9.js:1)

(用户从未登录过)。

一种奇怪的情况是,如果我有已登录的用户,则关闭Web浏览器并再次打开它,屏幕挂起大约10秒钟,然后出现另一个错误:

main.2a53201b6340bff6258a.js:1 User not logged in Error: Frame window timed out
   at t._error (main.2a53201b6340bff6258a.js:1)
   at t._timeout (main.2a53201b6340bff6258a.js:1)
   at e.invokeTask (polyfills.3efb6da5a4e032fb1cf9.js:1)
   at Object.onInvokeTask (main.2a53201b6340bff6258a.js:1)
   at e.invokeTask (polyfills.3efb6da5a4e032fb1cf9.js:1)
   at t.runTask (polyfills.3efb6da5a4e032fb1cf9.js:1)
   at t.invokeTask (polyfills.3efb6da5a4e032fb1cf9.js:1)
   at invoke (polyfills.3efb6da5a4e032fb1cf9.js:1)

但是,当屏幕加载时,我单击“登录”(因为没有登录),因此在加载组件之前会触发“经典” AuthGuard,因此我运行标准的startAuthentication()

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean | Observable<boolean> | Promise<boolean> {
        if (this.authService.isLoggedIn()) {
            return true;
        }
        this.authService.startAuthentication();
        return false;
    }

快速登录用户。我的问题是:就用户登录而言,该功能和signingSilent功能之间有什么区别?但是,由于确实如此,因此至少在时间和用户体验方面,行为不是预期的。我希望能够“如果可能的话登录用户,但不提示登录屏幕”。这有道理吗?

谢谢!

0 个答案:

没有答案