0

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!

Brock B.
  • 367
  • 1
  • 13

1 Answers1

1

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.

titleistfour
  • 305
  • 3
  • 12
  • 1
    This package has since been (sort of) abandoned. Strebl has recommended to use the official [Adldap2](https://github.com/Adldap2/Adldap2-laravel) package for Laravel. I have implemented this in our applications now. Support and documentation is solid, and the package is running flawlessly. I'm going to accept your answer for anyone else using the package still. – Brock B. Oct 12 '15 at 17:46
  • Ah ok cool, good to know. I'll check that other package out, might be something I can switch too easily. Thanks – titleistfour Oct 13 '15 at 18:24