什么是好的登录验证流程

What's a good Login Auth flow

我将如何实施如下所述的解决方案?插入 ember-simple-auth 这样的东西会更容易吗?我找到的所有示例都实现了自己的登录表单,这不是我想要的。我的登录名将存在于自己的域中。

场景:

  1. 用户访问 https://myapp.com
  2. 在某些初始化程序中,我发现它们没有 an/don 没有有效的访问令牌,所以我将它们重定向到 https://login.myapp.com?redirect_uri=https://myapp.com
  3. login.myapp.com 签署手头的用户递给他们一个访问令牌并将用户重定向到 https://myapp.com?access_token={token}
  4. Myapp 仅在这一次找到有效的访问令牌(来自 url)并设置一些用户已登录的变量。然后将令牌作为 header 承载添加到所有未来的 xhr 请求。

这是一种合乎逻辑的登录方法吗?我遗漏了一些基本缺陷?你知道任何教程做这样的事情吗?谢谢!

使用 Ember 简单身份验证可以很容易地实现该流程。当应用程序在重定向后再次启动时,您只需要 define a custom authenticator 验证会话。验证者的 authenticate 方法看起来……像这样:

authenticate: function(options) {
  return new Ember.RSVP.Promise(function(resolve, reject) {
    resolve({ token: /* the token you get from the query string */ });
  });
}

然后在初始化程序中使用身份验证器对会话进行身份验证就像:

this.get('session').authenticate('your-authenticator');