身份服务器发送令牌,但在客户端Angular应用上该令牌为空

问题描述

我正在将Angular 10与angular-oauth2-oidc库一起使用。更具体地说:

"angular-oauth2-oidc": "^9.2.2","angular-oauth2-oidc-jwks": "^9.0.0",

我们的SPA可以很好地启动登录流程,Identity Server会要求用户提供凭据,并使用以下令牌片段来回叫SPA:

http://ourhost.com/#access_token=XXXXXXX&token_type=Bearer&expires_in=7199

它到达我们的app.component的构造函数,它具有:

this.oauthService.configure(oAuthConfig);
this.oauthService.tokenValidationHandler = new JwksValidationHandler();
this.oauthService.loaddiscoveryDocumentAndTryLogin();
if (!this.oauthService.hasValidAccesstoken()) {
  this.oauthService.initImplicitFlow();
}

结果是hasValidAccesstoken()始终为false,因此登录流进入了无限循环。如果我们调试并使用getAccesstoken(),它将始终返回NULL。如果我们检查windows.location.href,它具有以下内容http://ourhost.com/#access_token=XXXXXXX&token_type=Bearer&expires_in=7199(出于空间和格式原因,输入XXXXX,但其中包含实际的令牌)

那么,我应该如何告诉angular-oauth2-oidc lib知道接收到的请求中的令牌?

我尝试了其他变体,例如:

this.oauthService.configure(oAuthConfig);
this.oauthService.tokenValidationHandler = new JwksValidationHandler();
this.oauthService.loaddiscoveryDocument();
this.oauthService.initImplicitFlow();

还有更多没有成功的尝试。 我还看到了一些示例,这些示例从具有相同问题的简单示例过渡到真正的巨大示例和复杂示例,而显然我在两行代码中缺少这些示例。

注意:我根本不需要刷新令牌

请按照正确的方向发送给我。 :)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)