如何使用锁 v11 从 auth0 passwordless 获取刷新令牌?

How do I get a refresh token from auth0 passwordless using lock v11?

我有一个有两个页面的老式 angularJs 应用程序。在这两个页面上,我都包含了 auth0 锁定脚本。

<script src="https://cdn.auth0.com/js/lock/11.9.0/lock.min.js"></script>

在这两个页面中,其中一个具有以下 js 指定 auth0 锁以允许用户登录:

new Auth0LockPasswordless(configuration.id,configuration.domain,
{
    allowedConnections: ['email'],
    passwordlessMethod: "link",
    auth: {
        redirectUrl: configuration.redirectUrl,
        responseType: 'token id_token',
        params: {
            scope: 'openid profile email offline_access'
        }
    }
}).show();

其他页面负责在他们点击电子邮件中的 link 后进行回调。

var lock = new Auth0LockPasswordless(configuration.id, configuration.domain);

lock.on('authorization_error',
    function(authResult) {
        console.log("DEBUG::AUTHRESULT::", authResult);
});

lock.on('authenticated',
    function(authResult) {
        console.log("DEBUG::AUTHRESULT::", authResult);
});

现在,我已经在请求范围内设置了 offline_access,并且在我的本地环境中,在进行身份验证时提示需要额外的权限(因此它正在通过)。但是,当我从 lock.on('authenticated', function(authResult).. 检查日志时,refreshToken 始终为 null。

网络上存在一些相互矛盾的文档,两种建议都认为锁定 return 刷新令牌。是否有人能够确认此代码是否会产生有效的 refreshToken?

正如@user44 在上面的评论中所说,您不应在 SPA(单页应用程序)中使用刷新令牌,因为它不是安全的客户端和安全存储它的方式。相反,使用 静默身份验证 方法来请求新的访问令牌。

https://auth0.com/docs/api-auth/tutorials/silent-authentication

根据您使用的 SDK,auth0-spa-js 或 auth0.js:

(免责声明:我在 Auth0 担任高级解决方案工程师)


更新(2020 年 5 月 7 日):

需要注意的是,Auth0 最近引入了 Refresh Token Rotation https://auth0.com/docs/tokens/concepts/refresh-token-rotation,Auth0 SPA SDK 也支持它