【问题标题】:Refresh access token ember刷新访问令牌 ember
【发布时间】:2016-04-18 22:28:19
【问题描述】:

我的应用访问令牌每 10 分钟过期一次。我使用 ember simple auth 进行身份验证,但它是一个自定义身份验证器,因为我拥有的不仅仅是用户名和密码字段。我想使用 ember-simple-auth-token,但是在我的适配器中调用授权:jwt,它不起作用,显然是因为我没有使用它的身份验证器。

所以,我正在考虑使用每十分钟更新一次令牌的服务,例如http://www.davekerr.co/programming/2015/05/17/add-a-polling-service-to-your-ember-app/,所以我的问题是如何覆盖 sessionData 令牌。

我的自定义授权文件代码如下所示:

import Ember from 'ember';
import Base from 'ember-simple-auth/authorizers/base';
export default Base.extend({
    authorize(sessionData, block) {
        if (!Ember.isEmpty(sessionData.token)) {
          block('Authorization',  'Bearer '+sessionData.token);
          block('Content-Type',  'application/json');
        }
    }
});

【问题讨论】:

    标签: authentication ember.js ember-simple-auth


    【解决方案1】:

    您应该在自定义身份验证器中执行此操作,因为身份验证器通常负责获取和管理令牌以及身份验证状态。您可以简单地安排一个计时器,在初始身份验证后的某个时间更新令牌。刷新令牌后,身份验证器可以触发会话将自动处理的sessionDataUpdated event

    查看implementation of the OAuth2PasswortGrantAuthenticator 以获取有关如何从身份验证器更新令牌的示例。

    【讨论】:

      猜你喜欢
      • 2019-06-29
      • 2020-07-12
      • 2019-01-13
      • 2018-08-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-14
      • 2020-01-09
      • 2021-08-23
      相关资源
      最近更新 更多