简体   繁体   English

Auth0 用户权限未在令牌中传递

[英]Auth0 user permissions not being passed in token

I created an auth0 backend api and a react client.我创建了一个 auth0 后端 api 和一个反应客户端。 Both applications correctly communicate to auth0 for authentication.两个应用程序都正确地与 auth0 通信以进行身份​​验证。 I can log in as a user on the react client, and then make a get request to the backend api using a bearer token to get access to a protected endpoint.我可以在 react 客户端上以用户身份登录,然后使用不记名令牌向后端 api 发出 get 请求以访问受保护的端点。 This follows https://auth0.com/docs/quickstart/backend/rails/01-authorization , however, I'm stuck when it comes to protecting endpoints additionally with specific scopes/permissions.这遵循https://auth0.com/docs/quickstart/backend/rails/01-authorization ,但是,在使用特定范围/权限额外保护端点时,我陷入了困境。

My understanding was that by creating a role in the auth0 settings, adding a specific scope/permission Y to that role, and by assigning user X to that role, the bearer token would automatically include that permission Y when user X correctly signs in in the react app.我的理解是,通过在 auth0 设置中创建一个角色,向该角色添加特定范围/权限 Y,并通过将用户 X 分配给该角色,当用户 X 正确登录时,不记名令牌将自动包含该权限 Y反应应用程序。 But when I hit the backend endpoints that's protected around that permission Y, it doesn't authorize me, so the scope seems to be missing.但是,当我访问受该权限 Y 保护的后端端点时,它没有授权我,因此范围似乎丢失了。 'Enable RBAC' and 'Add Permissions in the Access Token' are both enabled for the api.为 api 启用了“启用 RBAC”和“在访问令牌中添加权限”。

If anybody has experience with this, I'd greatly appreciate any help!如果有人有这方面的经验,我将不胜感激任何帮助!

A few things can be your issue here.有几件事可能是您的问题。 Once you have selected enable RBAC and Add Permissions in the Access Token , make sure you have added your permissions to the api.一旦您Add Permissions in the Access Token选择了enable RBACAdd Permissions in the Access Token ,请确保您已将您的权限添加到 api。 Next you will want to make sure your selected user has that permission associated with it under the users tab.接下来,您需要确保您选择的用户在用户选项卡下具有与其关联的权限。

Once you have this configured, your access token should have your permissions.配置完成后,您的访问令牌应该具有您的权限。 You can verify this by looking at the token generated on login on a site like https://jwt.io/ .您可以通过在https://jwt.io/等网站上查看登录时生成的令牌来验证这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM