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

时间:2016-01-22 01:25:21

标签: angularjs node.js authentication authorization restful-authentication

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

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

现在我使用Node.js和AngularJS,它们可能是目前构建网站最流行的组合,我希望有一种非常简单快捷的方式(甚至是第三方)来实现授权,就像在ASP中一样。 NET。

不幸的是,我只发现了一堆包含大量代码行的实现示例,并将我转变为了解令牌等内容的信息安全专家。以下是我发现的一些文章:< / p>

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/

有没有简单的方法来实现身份验证+授权+路由到未经授权的页面而无需编写如此多的代码行?

任何帮助都将深表感谢!

2 个答案:

答案 0 :(得分:2)

MeteorJS是一个基于节点的框架,带有一个嵌入式身份验证系统。它还在前端为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

以下是authentication section of the Meteor/Angular ToDo tutorial的链接。

答案 1 :(得分:1)

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