如何使用现有的服务器令牌与emberjs简单的验证 [英] How to use existing server token with emberjs simple auth

查看:118
本文介绍了如何使用现有的服务器令牌与emberjs简单的验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在执行这个库 ember-simple-auth 来管理身份验证我正在建设的emberjs应用程序(购物车)。

I'm currently implementing this library ember-simple-auth to manage authentication in the emberjs application (shopping cart) that I am currently building.

我遇到的困难是图书馆在登录后非常好地管理身份验证规则。

The difficulty that I encounter is that the library manages authentication rules after logging in very well but not before logging in.

所以这里是这样的场景:
应用程序必须与后端服务器通信,以便为每个用户检索会话令牌。这是必要的,使得用户可以使用会话数据临时将其项目保存在服务器端。

So here is the scenario: The application must talk to the backend server to retrieve a session token for every user. This is necessary so that the user can save their items temporarily in the server side using session data. Something that you would expect for a shopping cart.

然后当用户准备向前移动时,应用程序将显示登录屏幕,用户可以自己验证以进行结帐他们的项目。

Then when the user is ready to move forward the application will then display the login screen and the user can authenticate themselves to checkout their items.

然而,我似乎无法弄清楚如何使用simple-auth做到这一点。如果我创建一个从服务器获取令牌ID的自定义认证器,它将会将该会话标记​​为已认证,并且不会要求在authenticatedRoute上登录。

However, I can't seems to figure out yet how to do this using simple-auth. If I create a custom authenticator that just fetches token id from the server, it will mark the session as authenticated and will not ask for login on the authenticatedRoute.

一般来说,我想要做的是:

In general what I'm trying to do are:


  1. 客户访问该网站

  2. 应用程序从服务器获取会话令牌

  3. 客户点击并将项目保存到购物车中。数据与使用会话令牌的服务器同步

  4. 客户随时可以结帐并导航到结帐页面

  5. 应用程序拦截路由并重定向到客户登录路线,客户可以登录并恢复结帐。

  1. Customer visit the website
  2. The application fetches session token from the server
  3. Customer clicks around and saves item into the shopping cart. The data is synced with the server using the session token
  4. Customer ready to checkout and navigates to checkout page
  5. The application intercepts the route and redirect the customer to login route, where the customer can login and resume checkout.

我希望以上信息足够清楚。任何提示和帮助将不胜感激。谢谢。

I hope the above information is clear enough. Any hints and help will be much appreciated. Thanks.

推荐答案

我可能只能从用户实际登录的地方使用Ember Simple Auth。使用会话令牌来标识该篮子,我可能会在服务器端( POST / basket )上显式创建一个篮子,然后通过REST界面( PUT / baskets /:id / items 等等)。这样,您不会在客户端和服务器之间共享状态,并具有明确的界面。您也不需要滥用Ember Simple Auth,这可能仅仅在以后导致其他问题。当用户登录时,您只需将先前创建的购物篮分配给该用户,然后继续。

I would probably only use Ember Simple Auth from the point on where the user actually logs in. Before that instead of using a session token to identify the basket, I'd probably explicitly create a basket on the server side (POST /basket) and then add to that via a REST interface (PUT /baskets/:id/items or so). That way you're not sharing state between the client and the server and have a clear interface. You also don't need to "abuse" Ember Simple Auth which probably only leads to other problems later on. When the user logs in then, you simply assign the previously created basket to that user and go on.

这篇关于如何使用现有的服务器令牌与emberjs简单的验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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