Skip to content

Get specific attribut of an AD user #481

Answered by stevebauman
klepptor asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @klepptor,

You appear to be using both raw queries on your connection and models. I'd suggest sticking with models instead of running raw queries.

This should work for you:

use LdapRecord\Models\ActiveDirectory\User;
use LdapRecord\Models\ActiveDirectory\Group;

$user = User::findByOrFail('userPrincipalName, '[email protected]');

// $user->getDn(); // Get the users DN (if you need it).

$group = Group::findByOrFail('cn', 'Some Group');

if ($user->groups()->exists($group)) {
    // The user is a member of the group.
}

Here are the docs for user and group management for Active Directory:

https://ldaprecord.com/docs/core/v2/active-directory/users
https://ldaprecord.com/docs/core/v2/active-di…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by klepptor
Comment options

You must be logged in to vote
1 reply
@stevebauman
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants