Laravel Voyager LdapRecord SSO

151 Views Asked by At

I would like to use Voyager with an SSO connection.

I am trying to use LdapRecord to do this.

But the user models are different and I can't merge them.

Any ideas on how to use Voyager and LdapRecord together ?

1

There are 1 best solutions below

0
On BEST ANSWER

With Windows IIS, i enable Windows authentication for my site.

So, we can use $_SERVER['AUTH_USER']

namespace App\Http\Controllers\Common;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Auth;

use App\Http\Controllers\Commun\FunctionController;
use App\Models\User;

class ConnexionController extends Controller
{
    /**
     * 
     * @return array
     */
    public static function ConnexionSSO()
    {
        $authenticate = array(
            'state' => false,
            'message' => "You can't be authenticated."
        );

        $not_autorised = "";
        $ident = "";
        $agident = 0;
        $name = "";
        $surname = "";
        $email = "";

        if (App::environment() == 'local') {
            $ident = 'IDENT_LOCAL';
            $name = 'IDENT';
            $surname = 'FOR_LOCAL';
            $authenticate = [
                'state' => true,
                'message' => "You have been authenticated."
            ];
            $agident = 1;
        } else if (isset($_SERVER['AUTH_USER']) && $_SERVER['AUTH_USER'] != '')  {
            $ident = $_SERVER['AUTH_USER'];
            if (Str::contains($ident , '\\')) {
                $ident = explode('\\', $ident );
                $ident = $ident [1];
            }
            $user = FunctionController::DataAgentIdentifiant($ident);
            $name = $user['nom'];
            $surname = $user['prenom'];
            $email = $user['mail'];
            $select = "PS @nom='".$name." ".$surname."'";
            $dataUser = collect(DB::connection('sqlsrv')
                            ->select($select))
                            ->first();
            $agident = $dataUser->AgIdent;
            $authenticate = [
                'state' => true,
                'message' => "You have been authenticated."
            ];
        }

        return array(
            'authenticate'  => $authenticate,
            'not_autorised' => $not_autorised,
            'ident'         => $ident,
            'agident'       => $agident,
            'name'          => $name,
            'surname'       => $surname,
            'email'         => $email
        );
    }
}