Node.js & AngularJS 实现身份验证和授权机制的最快最简单的方法

Node.js & AngularJS quickest and simplest way to implement authentication & authorization mechanism

我正在使用 Node.js 和 AngularJS 构建一个项目。 我项目中的一些视图和操作需要授权。

在ASP.NET中,我曾经在用户凭据正确时简单地将用户ID或用户对象保存在Session中,然后在每个页面和操作中我会检查用户是否有权限,如果不,我会使用 Response.Redirect。就这么简单!

现在我使用 Node.js 和 AngularJS 这可能是当今构建网站最流行的组合,我希望有一个非常简单快捷的方法(即使是第三方)实现授权,就像 ASP.NET.

不幸的是,我只找到了一堆包含无数代码行的实现示例,使我成为一个了解令牌等事物的信息安全专家。这是我找到的一些文章:

Best practices for authentication and authorization in Angular without breaking RESTful principles?

http://frederiknakstad.com/2013/01/21/authentication-in-single-page-applications-with-angular-js/

https://www.theodo.fr/blog/2015/08/handling-basic-route-authorization-in-angularjs/

http://code.tutsplus.com/tutorials/token-based-authentication-with-angularjs-nodejs--cms-22543

http://www.kdelemme.com/2014/03/09/authentication-with-angularjs-and-a-node-js-rest-api/

有没有什么简单的方法不用写那么多行代码就可以实现认证+授权+路由到非授权页面?

任何帮助将不胜感激!

nodejs 模块和 jsonwebtoken、护照,passport-local passport local 用于本地策略,passport 用于身份验证,jsonwebtoken 用于创建身份验证令牌

MeteorJS 是一个基于节点的框架,带有 drop-in 身份验证系统。它还在 front-end 上首次 class 支持 AngularJS。

您首先要在命令行中添加相关帐户和UI 软件包。

meteor add accounts-password
meteor add dotansimha:accounts-ui-angular

您还可以添加 OAuth 提供程序包,例如 accounts-facebook 或 accounts-google。

然后在您的模板中添加 login-buttons 指令。

<login-buttons></login-buttons>

然后它会处理帐户创建、登录、忘记密码等。它还提供挂钩,因此您可以 add fields and values on account creation

这里是link到authentication section of the Meteor/Angular ToDo tutorial