How to authenticate existing users in new microservices

Viewed 94

We have laravel 5.2 with a user authentication system.

We use Angular.js for the UI app, which calls the laravel APIs with a user session.

User login with email and password and then use the project.

But now we are launching a new product and trying to follow the microservice architecture to make applications decoupled, scalable and maintainable with different teams.

Creating UI with React app, React app will call the new microservices to do the job.

The entry point of that new react app will be the still old app.

User login in the old app and then switch to new react app and then use the new Product within new APIs.

User Database is the same and users can use both products side by side.

The question here is that, how do we authenticate/authorize users in a new service?

1 Answers

Solution 1: use an SSO(Single Sign-On) system, like: https://github.com/aacotroneo/laravel-saml2

Solution 2: after user login, make an Http request(GuzzleHttp) from your old project to the new one:

Http::post('http://my-new-project.com/auth', [
    'email' => 'user@example.com',
]);

optionally make a queue/job,
then in your new project manually authenticate the user, for example:

$user = User::where('email', $request->input('email'))->first();
Auth::login($user);
Related