I'm trying to setup Active Directory authentication in Laravel 5.1, which I was able to get authenticating successfully using this package. The problem I'm encountering is that I cannot access any of the user properties or groups for the logged in user.
The documentation for the package isn't very thorough for how it's used, so I'm lost with how to access the properties of an Active Directory user.
I'm able to access the username by using Auth::user()->username;
but I believe that is returning the username from the User model. When I try to output the User using dd(Auth::user();
the only attributes available are the ones in the Users table in the database.
As per the documentation that is provided, adding a fields property to the auth.php configuration file should make them accessible, but it appears it isn't working properly. I have added 'fields' => ['displayname', 'givenname']
to the config file, but when running dd(\Auth::user()->displayname);
I'm receiving a null value.
Any help would be greatly appreciated. Thank you!
This is a late response, but I'm using the same package and had to do this to get it to work.
In config/auth.php
'fields' => [
'username' => 'samaccountname',
'full_name' => 'displayname',
'first_name' => 'givenname',
'last_name' => 'sn',
'description' => 'description',
'primary_group' => 'primarygroup',
'groups' => 'memberof',
],
Then I can access values like
Auth::user()->full_name
and so on...
I can also
if (in_array("Users", Auth::user()->groups)) {
# do something...
}
Hope that helps someone.