javascript - 如何使用 lock v11 从 auth0 无密码获取刷新 token ?

标签 javascript auth0 auth0-lock

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

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

在这两个页面中,一个具有以下 js,该 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();

另一个页面负责在他们单击电子邮件中的链接后进行回叫。
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 始终为空。

网络上有一些相互矛盾的文档,两种建议都锁定将返回刷新 token ,也不会返回刷新 token 。是否有人能够确认此代码是否应产生有效的 refreshToken?

最佳答案

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

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

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

  • https://auth0.github.io/auth0-spa-js/classes/auth0client.html#gettokensilently
  • https://auth0.com/docs/libraries/auth0js/v9#polling-with-checksession-

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

    更新(2020 年 5 月 7 日):

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

    关于javascript - 如何使用 lock v11 从 auth0 无密码获取刷新 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53026583/

    相关文章:

    javascript - 寻找有关如何从 sql 表创建图形并将其输出到网页的一些想法

    javascript - Google Analytics 通过自定义事件跟踪页面缩放级别

    javascript - React 和 Webpack 模块解析失败 :/testimonials. js 意外 token (6:4)

    java - 如何在 Spring Boot 中一起使用 auth0 和 swagger?

    javascript - 试图找出 auth0 自定义登录屏幕回调 url

    使用自定义 token 的 Firebase 身份验证给出 null uid

    node.js - 未找到授权 token - Express-JWT 和 Auth0

    JavaScript 数组原型(prototype), 'this' 没有 'push' 方法

    auth0 - 如何使用 Cypress 和 Auth0 测试单页应用程序

    javascript - Auth0 不会在电子邮件/密码的页面刷新时保持登录