我使用本指南 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',
});
我在 Auth0 的 token 中没有看到 user_metadata
范围:
我应该在哪里编写 scope
字段以使 Auth0 返回 user_metadata
?
P.S ui_locales
也不起作用。但我在文档 https://auth0.github.io/auth0-spa-js/interfaces/auth0clientoptions.html#scope 中看到它
最佳答案
您无法取回 user_metadata,因为它不是标准范围。
解决方法是将 user_metadata 从 Auth0 规则添加到 token ,如下所示:
// assumes you want to add this to the access token
context.accessToken['https://example.com/user_metadata'] = user.user_metadata;
有关向 token 添加自定义声明的更多阅读:https://auth0.com/docs/api-auth/tutorials/adoption/scope-custom-claims#custom-claims
关于javascript - Auth0 忽略范围选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57259132/