javascript - 如何使用 lock v11 从 auth0 无密码获取刷新令牌?
问题描述
我有一个老式的 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 检查日志时,它始终为空。
网络上有一些相互矛盾的文档,两种建议都锁定将返回刷新令牌,也不会返回刷新令牌。是否有人能够确认此代码是否应产生有效的 refreshToken?
解决方案
正如@user44 在上面的评论中所说,您不应该在 SPA(单页应用程序)中使用刷新令牌,因为它不是一个安全的客户端和安全存储它的方式。相反,使用静默身份验证方法来请求新的访问令牌。
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也支持
推荐阅读
- mysql - Laravel 的 ORM 是如何指定数据的排序值的?
- google-cloud-platform - Google Cloud Vision API 返回“429 - Quota Exceeded”
- google-cloud-platform - 运行 Google BigQuery 示例网络分析脚本,我得到一个语法错误: 期待:
- oracle - 为什么 Oracle 用 fetch 改变 rowid?
- java - 使用构建器模式编写数据类
- wordpress - 我可以让 Wordpress 搜索栏过滤器只提供来自博客而不是来自 woocommerce 的文章吗?
- mysql - 这段代码在数据库中发布对象可能有什么问题?
- python - 如何限制对未定义类/实例变量的访问?
- docker - Docker compose 没有从 swarm 主机中找到网络
- sql - XML 加载很慢。在读取具有以属性为中心的映射的 XML 文件时使用 text()