javascript - Auth0 忽略范围选项
问题描述
我使用本指南https://auth0.com/docs/quickstart/spa/react/01-login创建了带有 auth0 的 React 应用程序
一切正常。但现在我想在我的 React 应用程序中获取用户元数据。我已经用scope
字段扩展了我的 Auth0Client 构造函数,但它没有帮助。
const auth0FromHook = await createAuth0Client({
domain,
client_id: clientId,
redirect_uri: `${window.location.origin}/auth`,
response_type: 'id_token token',
ui_locales: 'ru',
audience,
scope: 'openid profile email user_metadata',
});
我没有看到user_metadata
来自 Auth0 的令牌范围:
我应该在哪里写scope
字段以使 Auth0 返回user_metadata
?
PSui_locales
也不行。但我在文档中看到它https://auth0.github.io/auth0-spa-js/interfaces/auth0clientoptions.html#scope
解决方案
你没有得到 user_metadata 因为它不是标准范围。
一种解决方法是将 user_metadata 从 Auth0 规则添加到令牌,如下所示:
// assumes you want to add this to the access token
context.accessToken['https://example.com/user_metadata'] = user.user_metadata;
有关向令牌添加自定义声明的更多信息:https ://auth0.com/docs/api-auth/tutorials/adoption/scope-custom-claims#custom-claims
推荐阅读
- javascript - 更新数组javascript索引上的数据并做出本机反应
- apache-spark - 在本地环境中使用 Apache Beam + SparkRunner 进行 Exactly-Once 测试
- python-3.x - 在运行此代码以训练 Deep Q 网络时,我收到“ModifiedTensorBoard”对象没有属性“_write_logs”的错误
- vue.js - 为 vue2-leaflet 添加搜索栏
- python - 无法在干净的 Ubuntu 安装上使用 pip3 导入“名称”错误
- javascript - SVG:文本显示在顶部和底部有间距
- vb.net - 除以零?!- 数据阅读器 OleDB VB.Net
- ggplot2 - 在同一图中绘制观察数据并通过两个模型(lm 和 lme)预测数据
- node.js - 密码不更新nodejs bcrypt
- amazon-web-services - AWS Elastic Beanstalk 和 Secret Manager