javascript - Auth0 忽略范围选项

标签 javascript reactjs auth0 scopes

我使用本指南 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 范围: enter image description here 我应该在哪里编写 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/

相关文章:

javascript - 具有共享原型(prototype)的instanceof

javascript - 获取 react native 中的所有列表数据

go - 使用 auth0 获取登录 acess_token 给 postman

reactjs - 授权然后使用 JWT token 与 Auth0 React 和 ASP.net core

javascript - 在 <script> 标签的 src 属性中使用通配符?

javascript - 什么可能导致 MVC 应用程序从数据库中提取后不在 IE 中显示当前信息?

reactjs - React-createRef() Api-this.child.current 为 null

javascript - React 上下文 useReducer 未正确更新

javascript - Auth0 在用户登录后使用我自己的数据库进行 CRUD

javascript - 无法执行重定向 302