Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel - Multiple projects with single signin

I just need some suggestion regarding single sign on for multiple laravel app. It's connected with same database and same users table. The concept is like ERP system where it has a multiple selection button which linked to the different app and the steps as below:

 1) Login/Register (APP1) 
 2) Redirect to ERP Home(APP1) 
 3) Select another app and redirect to app2(APP2) 
 4) Auto login based on APP1 authentication(APP2)

So the APP1 will be the main while the other app authentication dependent to APP1. Any suggestion? So far i have go through the laravel passport and jwt api documentation and its quite different from my goals.

Can i pass the session through the button HREF ? :(

Thanks!

like image 900
Suvin94 Avatar asked Nov 23 '25 04:11

Suvin94


2 Answers

Finally i can able to pass the user id through url and grab them from the route :) Here's the final code in case anyone having a same problem :)

Domain 1

Link the url through button

<a href="http://domain1.com/autologin?id={{ auth::id() }}&api_token=token">Pass uid</a>

Domain 2

Make sure the autologin route are inside web middleware.

web.php

Route::group(['middleware' => ['web']], function () {
    Route::get('autologin', function () {
        $user = $_GET['id'];
        Auth::loginUsingId($user, true);
        return redirect()->intended('/dashboard');
    });
});

Good luck and thanks ;)

like image 156
Suvin94 Avatar answered Nov 28 '25 16:11

Suvin94


I am just sharing my thoughts.

Process:

  1. Make a token system for communicating within two app.

  2. Token will carry a user id or any kind of unique identity.

  3. If APP1 generated temporary token get matched for APP2 then decode the token and get user unique identity.

  4. manually login the user in APP2

You can login any user manually.

Auth::login($user);
like image 24
Emtiaz Zahid Avatar answered Nov 28 '25 15:11

Emtiaz Zahid