Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lavelforum's avatar

Voyager SSO

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.

Do you have any ideas on how to use Voygaer and LdapRecord together?

0 likes
1 reply
lavelforum's avatar
lavelforum
OP
Best Answer
Level 1

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
	    );
    }
}

Please or to participate in this conversation.