在auth0锁定中,如何刷新id_token?

C. *_*oza 6 auth0

我正在构建一个cordova移动应用程序并尝试使用auth0锁定API.我在使用刷新令牌时遇到问题.我可以在authResult中检索刷新令牌,但无法弄清楚如何实际刷新id_token(我想我自己可以编写REST calsl)

在v9文档中,似乎曾经有过一种方法:https://auth0.com/docs/libraries/lock/v9/using-a-refresh-token

lock.getClient().refreshToken(refresh_token, function (err, delegationResult) {
  // Get here the new JWT via delegationResult.id_token
});
Run Code Online (Sandbox Code Playgroud)

但是在锁定v10中,似乎这种方法不再存在:https://auth0.com/docs/libraries/lock/v10/api

任何人都可以建议是否有办法使用锁API刷新令牌?

And*_*rew 1

首先,您需要在 HTML 中包含 Auth0 的脚本标记:

 <script src="https://cdn.auth0.com/js/lock/10.8/lock.min.js"></script>
Run Code Online (Sandbox Code Playgroud)

或者,如果您是从 npm 安装的,则可以要求 Auth0:

 var Auth0 = require("auth0-js");
Run Code Online (Sandbox Code Playgroud)

在 V10 中,您创建 Auth0 客户端的实例(与 Auth0Lock 实例分开),它具有以下功能refreshToken()

var auth0 = new Auth0({clientID: YOUR_CLIENT_ID, domain: YOUR_AUTH0_DOMAIN});
...
auth0.refreshToken(refresh_token_here, (err, resp) => {
    // resp: {expires_in: 36000, id_token: "id_token here", token_type: "Bearer"}
}
Run Code Online (Sandbox Code Playgroud)

使用以下getDelegationToken()函数也可以实现同样的效果:

auth0.getDelegationToken({
    client_id: YOUR_CLIENT_ID,
    grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
    refresh_token: refresh_token_here,
    scope: "openid",
    api_type: "auth0"
  }, (err, resp) => {
    // resp: {expires_in: 36000, id_token: "id_token here", token_type: "Bearer"}
  });
Run Code Online (Sandbox Code Playgroud)