README.md 2.46 KB
Newer Older
Dainis Abols's avatar
Dainis Abols committed
1
2
# LDAP Authorization Library for University of Latvia

3
- Version 2.1
4
5
6
7
8
9
## Requirements

- PHP 7.4
- PHP LDAP Extension

## Install via Composer
Dainis Abols's avatar
Dainis Abols committed
10
```
11
composer req luitd/lu-ldap-authorization
Dainis Abols's avatar
Dainis Abols committed
12
13
14
15
```

## Usage
``` php
16
$ldapAuth = new LDAP($ldapServer, $ldapDc);
17
$user = $ldapAuth->authorize($username, $password);
Dainis Abols's avatar
Dainis Abols committed
18
```
Dainis Abols's avatar
Dainis Abols committed
19
Variable `$user` will contain `null` on failed authorization and `LDAPUser` object on successfully authorization!
Dainis Abols's avatar
Dainis Abols committed
20

21
## LDAPUser Object 
22
23
24
25
26
27
28
29
30
31
32
33
34
| Type       | Getter                 | Description                       |
|------------|------------------------|-----------------------------------|
| int        | getUid()               | User identification               |
| Username   | getUsername()          | Username                          |
| Email      | getEmail()             | User e-mail address               |
| string     | getPhone()             | User phone number                 |
| string     | getFirstName()         | User given name                   |
| string     | getLastName()          | User surname                      |
| string     | getFullName()          | User full name                    |
| string     | getDisplayName()       | User display name                 |
| DateTime   | getPasswordChangedAt() | Timestamp of last password change |
| Collection | getGroups()            | Assigned user access groups       |
| Collection | getLDAPGroups()        | Assigned user access LDAP groups  |
Dainis Abols's avatar
Dainis Abols committed
35

Dainis Abols's avatar
Dainis Abols committed
36
37
38
39
40
41
42
43
44
45
46
47

### Important changes from 1.x

1) `Username` and `Email` has been remade into Type classes, use `toString()` to get plain values!
2) `Groups` and `LDAPGroups` have been remade into Collections, use `all()` to get content!
3) `cn` has been renamed to `fullName` to better show its true purpose!
4) `givenname` has been renamed to `firstName` to better show its true purpose!
5) `sn` has been renamed to `lastName` to better show its true purpose!
6) LDAPUser no longer contains `dc` return value!

All variables set to camelCase standard.

Dainis Abols's avatar
Dainis Abols committed
48
49
50
51
52
53
54
## Testing

```shell
 ./vendor/bin/phpunit  ./vendor/luitd/lu-ldap-authorization/tests (or /<test-file>)
```
| Test File               | Assertions |
|-------------------------|------------|
Dainis Abols's avatar
Dainis Abols committed
55
| Unit/LDAPUserTest.php   | 23         |
Dainis Abols's avatar
Dainis Abols committed
56
57
| Type/EmailTest.php      | 10         |
| Type/UsernameTest.php   | 10         |
Dainis Abols's avatar
Dainis Abols committed
58
| Functional/LDAPTest.php | 3          |
Dainis Abols's avatar
Dainis Abols committed
59
60
61
62

> LDAPTest requires LDAP connection data.
> 
> Specify your server and user details with `LDAPTest.php ldapServer=<your-server> ldapDC=<your-dc> ldapUser=<test-user> ldapPass=<test-pass>`