Replies: 1 comment 2 replies
-
Hi @splatEric! This is a great question -- I'll answer the best I can to help you out. TL;DR: Use I think this is definitely possible, and shouldn't be too difficult. Here is my initial thought process on how I would go about this:
Below are some examples (keep in mind, they are pseudo-code). Example use LdapRecord\Container;
use LdapRecord\Connection;
use App\Models\LdapConnection;
class LdapConnectionRegistratar
{
public function register()
{
LdapConnection::all()->each(function (LdapConnection $model) {
$connection = new Connection([
'hosts' => [$model->host],
// ...
]);
Container::addConnection($connection, $model->name);
});
}
} Example public function boot()
{
try {
// Register the LDAP connections from the database.
(new LdapConnectionRegistratar)->register();
} catch (PDOException $e) {
// Migrations haven't been ran yet.
}
} Example use LdapRecord\Container;
public function login(Request $request)
{
Container::setDefaultConnection($request->ldap);
$credentials = [
'mail' => $request->email,
'password' => $request->password,
];
if (Auth::attempt($credentials)) {
session()->set('ldap.connection', $request->ldap);
return redirect()->to('/dashboard');
}
return redirect()->back();
} I hope this helps! Let me know if you need further guidance 👍 |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Is there a way of setting up a generic LdapRecord model that could authenticate users from any number of Ldap configurations that are stored in the database, rather than needing each of the connections and LdapRecord classes to be hard coded in the system?
Essentially I want to be able to configure multiple ldap servers through an admin screen, storing the necessary details in the database. These different authentication options would be presented on the login screen for people to choose and authenticate against. I was hoping to avoid having to deploy new configuration each time a new LDAP server was being brought on stream to provide an authentication service.
Beta Was this translation helpful? Give feedback.
All reactions