简体   繁体   English

Ember Simple Auth子域重定向

[英]Ember Simple Auth subdomain redirects

I've been able to successfully setup multiple Ember applications with shared Ember Simple Auth cookie based authentication. 我已经能够使用共享的基于Ember Simple Auth cookie的身份验证成功设置多个Ember应用程序。 The next step of my journey is to setup proper redirects between applications. 我的旅程的下一步是在应用程序之间设置适当的重定向。 Hear me out. 听我说。

Scenario A (this works out of the box, yay!) 场景A(这是开箱即用的,是的!)

  • User tries to access domain.com/deep/link/resource 用户尝试访问domain.com/deep/link/resource
  • User is NOT logged in 用户未登录
  • User is redirected to domain.com/login to login via single sign-on component that uses Ember Simple Auth to save cookie with token 用户被重定向到domain.com/login以通过单点登录组件登录,该组件使用Ember Simple Auth来保存带令牌的cookie
  • After successful login user is redirected back to domain.com/deep/link/resource via previous transition 成功登录后,用户将通过之前的转换重定向回domain.com/deep/link/resource

Scenario B (this works out of the box, yay!) 场景B(这是开箱即用的,是的!)

  • User tries to access app-b.domain.com/deep/link/resource 用户尝试访问app-b.domain.com/deep/link/resource
  • User is already logged in via Ember Simple Auth cookie with token 用户已使用令牌通过Ember Simple Auth cookie登录
  • User can access app-b.domain.com/deep/link/resource route 用户可以访问app-b.domain.com/deep/link/resource route

Scenario C (this is what I need to achieve) 场景C(这是我需要实现的)

  • User tries to access app-a.domain.com/deep/link/resource 用户尝试访问app-a.domain.com/deep/link/resource
  • User is NOT logged in 用户未登录
  • User is redirected to domain.com/login to login via single sign-on component that uses Ember Simple Auth to save cookie with token 用户被重定向到domain.com/login以通过单点登录组件登录,该组件使用Ember Simple Auth来保存带令牌的cookie
  • After successful login user is redirected back to app-a.domain.com/deep/link/resource via previous transition on app-a subdomain 成功登录后,用户将通过app-a子域上的先前转换重定向回app-a.domain.com/deep/link/resource

Any help or guidance would be much appreciated. 任何帮助或指导将不胜感激。 I wonder if I can achieve Scenario C with Ember Simple Auth only, or if I need to write custom redirect logic in beforeModel on subdomains, etc. 我想知道我是否只能使用Ember Simple Auth实现Scenario C ,或者我是否需要在子域上的beforeModel编写自定义重定向逻辑等。

You'll be able get scenario C working by overriding the AuthenticatedRouteMixin 's beforeModel method . 您可以通过覆盖AuthenticatedRouteMixinbeforeModel方法来使场景C工作。 That will by default to an (Ember.js) transition to the login route but in your case you want sth. 这将默认为(Ember.js)转换到登录路由,但在您的情况下,你想要某事。 like window.location.replace('domain.com/login') and remember the current URL in a cookie or so. 比如window.location.replace('domain.com/login')并记住cookie中的当前URL。 In order to redirect to app-a.domain.com/deep/link/resource after the user logged in you'll need to override the ApplicationRouteMixin 's sessionAuthenticated method so that it redirects to the previous URL remembered in the cookie if that's present and falls back to the default behavior if not. 为了在用户登录后重定向到app-a.domain.com/deep/link/resource ,您需要覆盖ApplicationRouteMixinsessionAuthenticated方法,以便重定向到cookie中记住的先前URL(如果存在)如果没有,则回退到默认行为。

Overall, getting this to work should be pretty straight forward actually following these steps. 总的来说,实现这一点应该非常直接,实际上遵循这些步骤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM