AngularJS授权
Authorization with AngularJS
我们有一个带有 AngularJS (1.6) 和服务器端 运行 JAVA Spring MVC 的单页应用程序。身份验证后,服务器会传送 index.htm 文件,其中包含一个包含所有应用程序模块的主 JS 文件。
现在需要让某些模块对某些用户角色可用。实现这一目标的公认方法是什么?
我正在考虑在服务器端创建一个过滤器来捕获对该 JS 文件的请求,并根据用户角色,从 JS 文件中删除用户不应该看到的模块。
这似乎不是一个很好的解决方案,我想知道是否有更好的方法来实现这一点。
谢谢!!
你可以使用像 satellizer 这样的基于客户端的授权库,并从你的路由器实现授权
后台代码可以看下面的例子Login example. It uses rest http authentication and uses user name and password to in the headers to generate a encrypted header. See Rest Api。查看身份验证服务
if (LocalStorage.Get('auth') !== null) {
$http.defaults.headers.common.Authorization = LocalStorage.Get('auth');
return true;
}
else {
return false;
}
我们有一个带有 AngularJS (1.6) 和服务器端 运行 JAVA Spring MVC 的单页应用程序。身份验证后,服务器会传送 index.htm 文件,其中包含一个包含所有应用程序模块的主 JS 文件。
现在需要让某些模块对某些用户角色可用。实现这一目标的公认方法是什么?
我正在考虑在服务器端创建一个过滤器来捕获对该 JS 文件的请求,并根据用户角色,从 JS 文件中删除用户不应该看到的模块。
这似乎不是一个很好的解决方案,我想知道是否有更好的方法来实现这一点。
谢谢!!
你可以使用像 satellizer 这样的基于客户端的授权库,并从你的路由器实现授权
后台代码可以看下面的例子Login example. It uses rest http authentication and uses user name and password to in the headers to generate a encrypted header. See Rest Api。查看身份验证服务
if (LocalStorage.Get('auth') !== null) {
$http.defaults.headers.common.Authorization = LocalStorage.Get('auth');
return true;
}
else {
return false;
}