Angular2: how to share data across multiple subdomains?

2,123 views
Skip to first unread message

Christophe HOARAU

unread,
Apr 17, 2016, 11:47:54 AM4/17/16
to AngularJS
Hello,

This might not be directly related to angular2, but as it's the framework I want to use I would like to know if it's possible to implement in angular2, or plain javascript, a service that would be able to share data across multiple subdomains. The main purpose is to be able to share my session auth across all of the domains.
The only way I found seems to be by using a cookie on top domain. Isn't there any cleaner way to do this? I'd prefer to avoid cookie if possible.

Thanks a lot.

Sander Elias

unread,
Apr 18, 2016, 12:34:51 AM4/18/16
to AngularJS
Hi Christophe,

Use JWT in stead of cookies for you auth. This puts you in control over he whole process in stead of you browser handling it.
There is an 3rth party library for angular to make it even easier to use!

Regards
Sander

Sander Elias

unread,
Apr 18, 2016, 12:36:58 AM4/18/16
to AngularJS
Hi Christophe,

I linked in the angular 1 library. Here is the correct version.

Regards
Sander

Christophe HOARAU

unread,
Apr 18, 2016, 7:21:34 AM4/18/16
to AngularJS
Hi,

Thanks I'll have a deeper look tomorrow, but I don't think this would allow me to login across multiple sub-domain. I don't want to use cookies for authentication, but for sharing a data across my subdomain. But the counter part of this is that cookies are send with each request which I would like to be able to avoid.
I'm trying to find another way to achieve this but haven't found yet.
According to my understanding JWP will set a header on my request which is what I want to do, but it will not manage the offline storage of this header and will not help me to share it across my sub-domain which is where my problem is currently.

What I want is to be able to achieve some king of google like(and many other sites) authentication management : log on one domain for all subdomains.

Thanks.
Best regards.

Tito

unread,
Apr 18, 2016, 1:11:37 PM4/18/16
to AngularJS
I wonder if OAuth using passport might be the way to go for you

Thanks!

Christophe HOARAU

unread,
Apr 21, 2016, 1:58:22 PM4/21/16
to AngularJS
Thanks I'll have a look on passport,

But in the end the only cross browser solution seems to be cookies. It's quite a shame as I don't want to overload all my request with cookies, but I can't find any other way to achieve this.

Thanks.

Sander Elias

unread,
Apr 21, 2016, 10:18:12 PM4/21/16
to AngularJS
hi Christophe,

You can use JWT even across multiple domains, not only subdomains. This is exactly one of the reasons it's invented! Also, I do this in multiple projects, so this is known to work. 
If you need an server-side solution for your auth, you can indeed use passport. Passport has an way to work with JWT too.

Regards
Sander  

Christophe HOARAU

unread,
Apr 22, 2016, 12:20:27 AM4/22/16
to ang...@googlegroups.com
Hi,

Thanks I think I just find out what I needed to do. I just have to store my client side data on my login subdomain and send it through an url parameter for each other subdomains.

Thanks a lot.

Yours Sincerely/Cordialement

Christophe HOARAU

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/Tt5_8lZEOxs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

vikram singh

unread,
Dec 12, 2017, 12:55:55 AM12/12/17
to Angular and AngularJS discussion
 Hi Christophe,

I am working on a project and stuck in same kind of requirement where I need to login JWT, can you explain how you get it done on your app.
My requirement is to redirect user to their subdomain based on username like  vikram.myapp.com  if they register on myapp.com/signup or login through myapp.com/login

My requirement is something like launch27.com

Thanks in advance.
Reply all
Reply to author
Forward
0 new messages