简体   繁体   English

在角度2/4应用程序上对用户进行身份验证后的动态角色和权限

[英]Dynamic Roles and permissions after authentication the user on angular 2/4 application

I am creating an application with angular 2/4, Where my super-admin will create different tenants/roles and give access to different pages/features(permissions) so both things will be dynamic. 我正在使用angular 2/4创建一个应用程序,我的超级管理员将创建不同的租户/角色,并允许访问不同的页面/功能(权限),因此这两件事都是动态的。

I can able to retrieve the pages and display them on menu. 我可以检索页面并在菜单上显示它们。 Implemented the menu by using this article : https://webcake.co/automating-your-main-nav-in-a-modular-angular-2-app/ 使用这篇文章实现了菜单: https//webcake.co/automating-your-main-nav-in-a-modular-angular-2-app/

Now I also want to guard the route so a user will not access the feature with manually typing the URL. 现在我还想保护路由,以便用户不会通过手动输入URL来访问该功能。

Need some more clarification of how to make dynamic routes or navigation which is getting from database. 需要更多说明如何从数据库获取动态路由或导航。

Is there any way to do role-based authorization with dynamic role name and dynamic feature permissions? 有没有办法使用动态角色名称和动态功能权限进行基于角色的授权?

Can any one help on this. 任何人都可以为此提供帮助。

I'm a little late, but this particular guide helped me smooth out some things, if you're comfortable with JWT. 我有点晚了,但如果你对JWT感到满意的话, 这个特别的指南帮助我顺利完成了一些事情。 The gist of it is that you'll have to send the roles/permissions of the user on login from the server. 它的要点是您必须在登录时从服务器发送用户的角色/权限。 Your Angular app should store this "metadata" locally (in, say, localstorage ) and use it to guard your routes. 您的Angular应用程序应该在本地存储此“元数据”(例如,在localstorage )并使用它来保护您的路由。 Guarding your routes can be easily done by Angular Guards. Angular Guards可以轻松保护您的路线。

Keep in mind, though, that this only protects you so far. 但请记住,这只能保护你到目前为止。 Anybody can edit their localstorage (or sessionstorage or cookies for that matter), so your API end-points themselves must be guarded properly so that even if an unauthorized user somehow accesses your protected Angular routes, he/she will be rejected by the API. 任何人都可以编辑他们的localstorage (或者sessionstorage或cookie),因此必须正确保护您的API端点,以便即使未经授权的用户以某种方式访问​​受保护的Angular路由,他/她也将被API拒绝。

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

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