nusait / nuldap-laravel by nusait

266
0
7
Package Data
Maintainer Username: nusait
Maintainer Contact: vahidazam@gmail.com (Vahid Azam)
Package Create Date: 2016-02-27
Package Last Update: 2016-07-22
Language: PHP
License: Unknown
Last Refreshed: 2024-04-25 15:13:53
Package Statistics
Total Downloads: 266
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 7
Total Forks: 1
Total Open Issues: 3

NuLdap

This is a LDAP package meant for Northwestern University. (But can be extended for other entities)

Installation via Composer

composer require nusait/nuldap-laravel

Then update composer

composer update

Laravel

Add the service provider to config/app.php

Nusait\Nuldap\NuldapServiceProvider::class,

Publish the config:

php artisan vendor:publish --provider="Nusait\Nuldap\NuldapServiceProvider" 

To use the fake Ldap, make sure to add to your .env file the line:

ldap_fake=true

When using NuldapFake, any search will return a user with pre-filled data using Faker. Whatever search term you provide for a field will return as the value for that field, i.e. a searchNetid('asdf') will return a user with ['netid'] = 'asdf'. In order to simulate not finding a user, prepend the query with nf-, i.e. searchNetid('nf-blah') and it will not find that user.

New Instance:

$ldap = \App::make('ldap') or $ldap = app('ldap')

Validate:

$ldap->validate($netid, $password);

returns a boolean

Searching:

You can search by netid, email, emplid, or studentid.

$ldap->search('netid', $netid);
$ldap->search('email', $email);
$ldap->search('emplid', $emplid);
$ldap->search('studentid', $studentid);

This returns the raw ldap metadata.

You can also search using the magic methods:

$ldap->searchNetid($netid);
$ldap->searchEmail($email);
$ldap->searchEmplid($emplid);
$ldap->searchStudentid($studentid);

Parsing User

$ldap->parseUser($ldapUser [, $transformer ]);

You can parse the raw metadata of a user to create an associative array of the user. You can pass your own transformer into the function. The transformer must implement the TransformerInterface in the Contracts folder.

The default transforms maps the following keys and value:

return [
    'netid'       => $this->getSetValueOrNull($ldapUser, 'uid'),
    'phone'       => $this->getSetValueOrNull($ldapUser, 'telephonenumber'),
    'email'       => $this->getSetValueOrNull($ldapUser, 'mail'),
    'title'       => $this->getSetValueOrNull($ldapUser, 'title'),
    'first_name'  => $this->getSetValueOrNull($ldapUser, 'givenname'),
    'last_name'   => $this->getSetValueOrNull($ldapUser, 'sn'),
    'displayname' => $this->getSetValueOrNull($ldapUser, 'displayname'),
    'emplid'      => (int)$this->getSetValueOrNull($ldapUser, 'employeenumber'),
    'studentid'   => (int)$this->getSetValueOrNull($ldapUser, 'nustudentnumber')
];