【问题标题】:Angular 7 - Auth0 - parseHash response nullAngular 7 - Auth0 - parseHash 响应为空
【发布时间】:2019-10-26 06:15:45
【问题描述】:

Auth0 问题。

我的应用程序在浏览器刷新时注销后重新触发登录事件,并且用户配置文件出现问题。我在身份验证服务中追踪到 parseHash:

  this.auth0.parseHash({ hash: window.location.hash }, (err, authResult) => {
  ...
  }

使用 ngrx 效果触发:

  @Effect()
  init$ = defer(() => {
    const userData = localStorage.getItem("user");

    if (userData != null && userData != 'undefined') {
       let authActionObservable = of(new Login({user: JSON.parse(userData)}));
       this.authService.handleAuthentication();
       return authActionObservable;
    }
    this.authService.handleAuthentication();
  });

似乎 this.auth0.parseHash 在页面刷新后为 authResult 和 err 返回 null 但在初始登录时 authResult 填充正确。

从技术上讲,登录是成功的,我得到了令牌。我检查了整个配置、域等,一切似乎都很好。我也尝试过使用 { hash: window.location.hash }。

【问题讨论】:

    标签: angular typescript authentication auth0


    【解决方案1】:

    问题在于,包含服务令牌的内存变量的状态在每次页面刷新时都会重置。一旦我重新初始化服务构造函数中的值,问题就消失了。

    这里以 localStorage 为例说明我的意思:

      constructor(public router: Router, private store: Store<State>, private http: HttpClient) {
        this._idToken = localStorage.getItem("Auth0IdToken");
        this._accessToken = localStorage.getItem("Auth0AccessToken");
        this._expiresAt = parseInt(localStorage.getItem("Auth0ExpiresAt"));
      }
    

    【讨论】:

    • 您已经展示了如何在刷新期间持久化数据,但没有展示如何处理持久化的值。您如何处理这些值?
    【解决方案2】:

    我经常看到 HAR 文件被捕获以帮助缩小在注销工作流程期间发生的确切范围。如果没有确切地看到有几件事,我可以建议看看。

    1. 查看Logout Documentation
    2. 查看how to handle Redirects after logout 上的此文档并评估您处理注销的方式。
    3. 您需要确保将 client_id 参数传递给注销端点,同时在客户端级别设置允许的注销 URL。

    现在我可能对这里发生的事情的核心是错误的,但袖手旁观是一个很好的基本起点。谢谢!

    【讨论】:

      猜你喜欢
      • 2018-07-21
      • 1970-01-01
      • 2019-06-20
      • 2018-05-17
      • 1970-01-01
      • 2019-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多