Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distributed application with authentification (Question) #24

Closed
THEJean-Kevin opened this issue Jun 6, 2019 · 7 comments
Closed

Distributed application with authentification (Question) #24

THEJean-Kevin opened this issue Jun 6, 2019 · 7 comments

Comments

@THEJean-Kevin
Copy link
Contributor

Hello,

I would like to say first 'THANKS YOU' for your work.

I'm trying to create several FeathersjsApps where each app has its own authentication system.

I managed to do the setup so that the applications communicate with each other on the server side.

The current concern is that I don't know how to do it on the client side to authenticate on each App

var socket = io('http://localhost:3030');
const client = feathers();
client.configure(feathers.hooks())

client.configure(feathers.socketio(socket));
// Use localStorage to store our login token
client.configure(feathers.authentication({
  storage: window.localStorage
}));
client.authenticate({
      strategy: 'local',
      email: '[email protected]',
      password: 'password'
}).then(()=>{
}).catch((error)=>console.log(error))

I don't know how to get something like.
client.App('firstAuth').authenticate

Link to github code : https://github.com/THEJean-Kevin/feathersjs-test-distributed

@claustres
Copy link
Member

Thanks, we would need more information to help you. First why do you need 2 different auth systems ? Are these systems sharing the same user DB or not (ie the same user has different account, one for each app or a single account) ? Does each app work as a standalone solution from the user point of view (ie different domains, etc.) and collaborate for some parts with the other app ?

There are different ways to manage this depending on your context, here are some ideas:

  • if your user entry point is only eg the first app and the second app is just a microservice used by the first one then you don't need authentication on the second app and should not be exposed publicly only internally in your backend
  • if each app is a user entry point (e.g. you want separates API on separate domains) they can use a shared secret so that the JWT generated by one will be valid for the other one, a kind of machine-to-machine SSO
  • otherwise you can also create a frontend proxy, ie an app that will centralize authentication all others microservice apps not exposed publicly only internally in your backend

This is a draft article that will be submitted to Feathers blog, it might help: https://medium.com/@luc.claustres/a-use-case-of-microservices-with-feathersjs-building-a-geospatial-platform-56373604db71. Some interesting discussions as well: feathersjs/feathers#332 (comment), feathersjs/feathers#939 (comment).

@THEJean-Kevin
Copy link
Contributor Author

THEJean-Kevin commented Jun 6, 2019

Every system have own DB.
The user have one account for each app.
Each app work as a standalone solution from the user point of view but collabore from server point of view.

For exemple if I have an mail app and phone App.

Mail auth => email+ password
Phone auth => number + PIN

If I open mail.html I need to connect to the mail auth but not on phone app.
and vice versa.

But from server mail app. I need to be able to get the phone number for exemple.

Sory if my english was not correct. I french dev ;)

@THEJean-Kevin
Copy link
Contributor Author

I'm just stupid I found how to use correctly authentification.

I have a last question, What is happen when 2 services have the same name?
(example :
mail APP with service text
phone APP with service text)
if I call from hook "context.app.service.text". It's call text from Mail or from phone?

@claustres
Copy link
Member

claustres commented Jun 6, 2019

Could you please share what the problem was and how you solved it so that if others seek for a similar issue they will find some information.

You should not have services with the same name except if you use replication (multiple instances of the same app for scaling purpose). In this case cotejs will load balance requests between services: https://github.com/dashersw/cote#requester.

@claustres
Copy link
Member

By the way we've just added some options to select which services to "import" and "export": https://github.com/kalisio/feathers-distributed/blob/master/README.md#configuration-options.

For instance it probably does not make sense to distribute your user services between apps.

@THEJean-Kevin
Copy link
Contributor Author

It's not user I want to distribute. But in all app I want to create a "main" serviceto create custom method. So I need export this.

@THEJean-Kevin
Copy link
Contributor Author

An for my porbleme of authentification, I just need to connect to the correct port with socket

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants