Ember.js 当登录页面位于另一个系统上时使用ember simple auth

Ember.js 当登录页面位于另一个系统上时使用ember simple auth,ember.js,ember-simple-auth,Ember.js,Ember Simple Auth,登录到我们的应用程序的页面是托管在另一台机器上的jsp。我已通过允许调用window.location.replace来修改authenticated route mixin,成功地使请求触发到此计算机,如果路由以http开头 beforeModel(transition) { if (!this.get('session.isAuthenticated')) { Ember.assert('The route configured as Configuration.au

登录到我们的应用程序的页面是托管在另一台机器上的jsp。我已通过允许调用
window.location.replace
来修改
authenticated route mixin
,成功地使请求触发到此计算机,如果路由以http开头

  beforeModel(transition) {
    if (!this.get('session.isAuthenticated')) {
      Ember.assert('The route configured as Configuration.authenticationRoute cannot implement the AuthenticatedRouteMixin mixin as that leads to an infinite transitioning loop!', this.get('routeName') !== Configuration.authenticationRoute);

      transition.abort();
      this.set('session.attemptedTransition', transition);
      debugger;
      if (Configuration.authenticationRoute.startsWith('http')) {
        window.location.replace(Configuration.authenticationRoute);
      } else {
        this.transitionTo(Configuration.authenticationRoute);
      }
    } else {
      return this._super(...arguments);
    }
  }
这是可行的,但当我被重定向回我的应用程序时,ember simple auth认为我不再登录,并将我重定向回远程机器,然后以无限循环的方式将我发送回应用程序

显然,我需要设置一些东西,让ember simple auth知道它实际上已登录。为什么它不自动地这样做?我做错了什么

我对oAuth很陌生,所以我可能会错过一些基本的设置

这是网址

  ENV['ember-simple-auth'] = {
    authenticationRoute: 'https://our-server.com/opensso/oauth2/authorize?client_id=test-client-1&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A4200%2Fsecure'
  };

与其修改
AuthenticatedRouteMixin
,我建议您在验证器中处理特定于应用程序的登录,验证器是一个关键配置原语

据我所知,在首次加载应用程序并检查用户是否经过身份验证时,Ember Simple Auth将使用
还原
方法,该方法定义为Authenticator API的一部分

您可以从
restore
返回一个承诺,该承诺将解析或拒绝以指示用户是否经过身份验证。如何检查这一点是auth系统的一个实现细节

我不知道您是如何在客户端上存储凭据的(如果您能提供更多详细信息,那就太好了),但下面是一个使用cookies进行身份验证的示例流程:

  • 余烬启动后,ESA尝试
    恢复
    会话
  • restore
    向Java服务器上的安全“虚拟”资源发出一个简单的AJAX请求,并检查它是否返回200或401
  • 我们拿到了401。用户未通过身份验证,因此在从
    restore
    返回的承诺中拒绝
  • 让ESA将用户重定向到您的身份验证路由。理想情况下,不要覆盖
    AuthenticatedRouteMixin
    ——而是在身份验证路由中使用
    beforeModel
    钩子将用户发送到JSP登录页面
  • 用户根据JSP表单正确地进行身份验证
  • 在其响应中,Java服务器将某种加密、签名的会话cookie(这是它通常与Rails一起工作的方式)设置为凭据。此外,它会将重定向发送回您的余烬应用程序
  • 灰烬再次启动,ESA再次调用
    restore
  • restore
    再次ping您的Java服务器,获得200分(感谢cookie),从而解决其承诺
  • ESA了解到用户已通过身份验证,并重定向到“身份验证后的路由”
  • 请记住,在其核心,ESA只能向客户端指示后端是否认为它“已验证”ESA永远不能用于拒绝对资源的访问——只能根据从后端听到的最后一件事在客户端上显示不同的内容

    让我知道这些是否有用