架构登录系统均值叠加? [英] Architecture for login system on MEAN stack?

查看:124
本文介绍了架构登录系统均值叠加?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发的平均堆栈(MongoDB中,前preSS,AngularJS和node.js的)上的Web应用程序。我正在开发一个登录系统,也将有一定的保护,只有登录用户可以访问它们的角路线。我试图想接近这种架构的最佳方式。

I'm developing a web app on the MEAN stack (MongoDB, Express, AngularJS, and node.js). I'm developing a login system, and will also have some of the Angular routes protected so that only logged-in users can access them. I'm trying to think of the best way to approach the architecture of this.

我想目前的工作流程:


  • 用户通过AngularJS形式,它发送一个HTTP POST到防爆preSS端点登录英寸端点验证对数据库用户,并使用OAuth凭证以及一个cookie响应。两者都存放在以后的验证蒙戈数据库。

  • 一旦AngularJS收到登录响应,它采用NG-饼干存储接收的cookie,并存储用户的服务OAuth令牌。

  • 现在每次在AngularJS路由变化,用户服务是用于确保该Cookie仍然是它蒙戈数据库比较饼干(这将是采用了棱角分明的决心API调用合法...这会创建一个明显的滞后?)

  • 当用户点击注销或Cookie过期,饼干和OAuth令牌都是从数据库中删除,将不再有效。

请问这种做法是否合理?它是安全的,而且会是比较有效/快速的执行力?

Does this approach make sense? Is it secure, and will it be relatively efficient/quick in execution?

推荐答案

我结束了我原来的工作流程相结合的防爆preSS的权威性例如,看到的此处。它如下所示:

I ended up combining my original workflow with Express's auth example, seen here. It is as follows:


  • 当用户最初加载应用程序,一个HTTP调用来检查某会话用户已经存在一个Ex preSS终点的。如果是这样,用户存储在 $ rootScope 并认为登录。

  • 的AngularJS路由变化,同样的端点被访问任何时候。路由保护以类似于所描述<方式的方式指定href=\"http://blog.brunoscopelliti.com/deal-with-users-authentication-in-an-angularjs-web-app\">here.如果端点曾经返回会话不存在, $ rootScope.user 没有设置(如果它需要),用户被重定向到登录页面。

  • 当处理登录表单,它发布到一个Ex preSS端点。端点检索来自MongoDB的用户(如果它存在),并尝试进行散列的口令。如果它是一个比赛,该用户的会话设置,存储在蒙戈DB和端点返回用户对象(用在$ rootScope保存为previously提到)。

  • 任何进一步的端点访问的任何时间,功能首先,通过它可以确保一个会话的任​​何数据发送到客户端之前就存在限制函数传递。它返回一个 401 ,如果会话不存在,然后使用的这个HTTP拦截来未设置 $ rootScope.user 并重定向到登录屏幕。

  • 当用户点击的角边注销,会议被取消设置,并从蒙戈DB中删除, $ rootScope.user 设置为null,用户被重定向到头版。

  • When user initially loads the app, an http call is made to an Express endpoint that checks if a session exists already for the user. If so, the user is stored in $rootScope and considered logged in.
  • Any time the AngularJS route changes, the same endpoint is accessed. Route protection was specified in a way similar to that described here. If the endpoint ever returns that no session exists, $rootScope.user is unset (if it needs to be), and the user is redirected to the login page.
  • When the login form is processed, it posts to an Express endpoint. The endpoint retrieves the user from the mongoDB (if it exists), and attempts to hash the password. If it's a match, the user's session is set, stored in the mongo DB, and the endpoint returns the user object (used to store in the $rootScope as previously mentioned).
  • Any time any further endpoints are accessed, the functions are first passed through the restrict function which ensures that a session exists before sending any data to the client. It returns a 401 if no session exists, which is then handled on the Angular side using this HTTP interceptor to unset $rootScope.user and redirect to the login screen.
  • When the user clicks "log out" on the Angular side, the session is unset and deleted from the mongo DB, $rootScope.user is set to null, and the user is redirected back to the front page.

这篇关于架构登录系统均值叠加?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆