There's this package https://github.com/Adldap2/Adldap2-Laravel
How to join Laravel 5.4 to Windows Active Directory server?
Is it possible to do that? Where to configure it? Thanks.
Yes it's possible and not that hard, maybe the package work. I made it once without a package, but unfortunately my code is long gone as I don't work there anymore.
Thanks @fraserk Have u used it b4? Cos there is a not shown Note: OpenLDAP support is experimental, success may vary. looks like it is for open LDAP.
Anyway, it needs pho ldap extension which I can get in IIS web tool or I need to download it? Thanks.
@EmilMoe if u can find the code without using the package, that may be easier. Unfortunately, u don't have the code anymore.
@fraserk Also, I read the instruction of the package. Looks like it doesn't show where to configure the server IP address or credential info, etc? Thanks.
@achieve100 No I haven't use is as yet, but plan on using for an upcoming project.
Here is the configuration setting file.
https://github.com/Adldap2/Adldap2/blob/master/docs/configuration.md
// Create the configuration array.
$config = [ // Mandatory Configuration Options
'domain_controllers' => ['corp-dc1.corp.acme.org', 'corp-dc2.corp.acme.org'],
'base_dn' => 'dc=corp,dc=acme,dc=org',
'admin_username' => 'admin',
'admin_password' => 'password',
// Optional Configuration Options
'account_prefix' => 'ACME-',
'account_suffix' => '@acme.org',
'admin_account_suffix' => '@acme.org',
'port' => 389,
'follow_referrals' => false,
'use_ssl' => false,
'use_tls' => false,
'timeout' => 5,
// Custom LDAP Options
'custom_options' => [
// See: http://php.net/ldap_set_option
LDAP_OPT_X_TLS_REQUIRE_CERT => LDAP_OPT_X_TLS_HARD
]
];
// Create a new Adldap Provider instance.
$provider = new \Adldap\Connections\Provider($config);
@fraserk Where is this config file in laravel 5.4? Thanks.
@achieve100 there's a LDAP function for PHP built in, it's basically what you need.
You can see an example here https://www.exchangecore.com/blog/how-use-ldap-active-directory-authentication-php/
I recommend you in any case to download a LDAP browser where you can get a feeling of how it's structured. Windows Active Directory (the application) isn't very helpful as it's made more user friendly.
Thanks @EmilMoe But, our organization is using Windows AD. That's why. Anyway, thanks for your info.
@fraserk can I ask what php ldap extension version which is compatible to Laravel 5.4 you downloaded? Thanks.
@fraserk I have started reading the github and making a test in my system. Looks like the system can't find the version. Below is the result. Please advise.
PS C:\inetpub\wwwroot\shfinventory> composer require adlap2/adldap2-laravel
[InvalidArgumentException]
Could not find package adlap2/adldap2-laravel at any version for your minimum-stability (stable). Check the package spelling or your minimum-stability
require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-suggest] [--no-update] [--no-scripts] [--update-no-dev] [--update-with-dependencies] [--ignore-platform-re
qs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--] [<packages>]...
PS C:\inetpub\wwwroot\shfinventory> composer require "adlap2/adldap2-laravel"
[InvalidArgumentException]
Could not find package adlap2/adldap2-laravel at any version for your minimum-stability (stable). Check the package spelling or your minimum-stability
require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-suggest] [--no-update] [--no-scripts] [--update-no-dev] [--update-with-dependencies] [--ignore-platform-re
qs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--] [<packages>]...
PS C:\inetpub\wwwroot\shfinventory> composer require adlap2/adldap2-laravel:3.0.*
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package adlap2/adldap2-laravel could not be found in any version, there may be a typo in the package name.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
Installation failed, reverting ./composer.json to its original content.
@fraserk I want to share to you and others. After I used "composer update" command, my whole testing web site can't be browsed anymore. Where I can check the log for issue? I luckily can resolve it by running "composer dump-autoload".
@achieve100 First thing, you had a typo.
//You have
composer require adlap2/adldap2-laravel
//It should be
composer require adldap2/adldap2-laravel
Thanks. @fraserk You got me and I could run the following. Unfortunately, my web site can't be browsed again and even php artisan r:l couldn't show anything now. I think I may be able to run composer dump autoload again. But, I would like to check with you first why it's like that? Thanks.
PS C:\inetpub\wwwroot\shfinventory> composer require adldap2/adldap2-laravel
Using version ^3.0 for adldap2/adldap2-laravel
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
- Installing adldap2/adldap2 (v7.0.15): Downloading (100%)
- Installing adldap2/adldap2-laravel (v3.0.4): Downloading (100%)
Writing lock file
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan optimize
Generating optimized class loader
The compiled services file has been removed.
PS C:\inetpub\wwwroot\shfinventory> php artisan r:l
@fraserk I need to use composer dump-autoload to bring the web site back. But, it looks like the ldap has been configured in Laravel. Then, I configured the config/adldap.php file.
Then, I don't quite sure if I need to perform all methods on my Adldap connection through its facade or inject the Adldap interface into all of my controllers? Please advise.
Hello, actually, I just configured HomeController.php. The local user is working still. But, the LDAP user is not working yet I think coz I can't login.
Is there any tool to prove it's configuring successfully for Laravel. Please advise. Thanks.
Like i said before, I haven't used this package as yet.
Here's how to interact with AD
// Finding a user.
$user = Adldap::search()->users()->find('john doe');
// Searching for a user.
$search = Adldap::search()->where('cn', '=', 'John Doe')->get();
// Authenticating against your LDAP server.
if (Adldap::auth()->attempt($username, $password)) {
// Passed!
}
// Running an operation under a different connection:
$users = Adldap::getProvider('other-connection')->search()->users()->get();
// Creating a user.
$user = Adldap::make()->user([
'cn' => 'John Doe',
]);
$user->save();
I could see it in the link you provided too. But, I am not sure where to put those coding. Thanks.
Windows AD is just a version of the LDAP protocol
Newer versions of Active Directory use restful api. Azure AD even uses Oauth 2 for authentication (facebook, google etc). Older ones use soap (yuck) and thats what most of the packages are for.
You may be trying to use "stuff" you don't really need, yet really is an everyday occurrence as a lot of MS software (dynamics, office 365 older nav, pims etc) all come with AD.
@jekinney I agree and I heard all about it. So, what package or method you can introduce to accomplish to join Laravel 5.4 to Windows AD? Thanks.
If it's the newer one then your only real method is updating the login if you want to store user's locally or user model in general (not hit sql but your endpoints in AD).
As far as models go they represent data. Data from anywhere or anything. Doesn't need to map to a database table, it can map to API end points.
Set up methods to get a user, verify a user etc and off to the races. Like I said it all depends on what version of AD you are using. You really can't get say 2009 or even 2013 to work the same as 2016 or azure AD not even packages can encompass all the different versions
Hello, I have followed the Aldap2 github link to install and configure especially I have verified with our sy's admin that every information is correct for Aldap. What else I can do to verify the verification? Thanks.
Hello, I found out authenticate which is original Laravel login users method includes lots of function to let users login or not. Should I disable this method and configure login controller? Pls help how to configure properly? Thanks.
@fraserk have u configured yet? Thanks.
i have implement adldap2 to use my office AD authentication yesterday.
use this guide: https://github.com/jotaelesalinas/laravel-simple-ldap-auth
you must have php-mbstring and php-ldap installed
if you follow the instruction carefully you will have laravel AD authentication work with third party trial server, then you can modify the configuration with your own AD. I have successfully implemented it.
one tips, if your username not work, try to append your domain to get a FQDN. for example if you can't login with user 'johndoe', try modify the code ($userdn) in LoginController@attemptLogin :
$userdn = $username . '@mydomain.com';
good luck
Can you share your ldap.php and ldap_auth.php please!
Thanks for the help guys. appreciated
@sunnyboy I already gave you mine which works in production here https://laracasts.com/discuss/channels/laravel/adldap2-laravel-with-windows-active-directory?page=1#reply=543568
Please or to participate in this conversation.