diff --git a/README.md b/README.md index 33e8e39..6221199 100644 --- a/README.md +++ b/README.md @@ -9,72 +9,77 @@ ## Installation Insert Adldap2-Laravel into your `composer.json` file: - - "adldap2/adldap2-laravel": "1.2.*", +```json +"adldap2/adldap2-laravel": "1.2.*", +``` Then run `composer update`. Once finished, insert the service provider in your `config/app.php` file: +```php +Adldap\Laravel\AdldapServiceProvider::class, +``` - Adldap\Laravel\AdldapServiceProvider::class, - Then insert the facade: - - 'Adldap' => Adldap\Laravel\Facades\Adldap::class +```php +'Adldap' => Adldap\Laravel\Facades\Adldap::class +``` Publish the configuration file by running: - - php artisan vendor:publish +```bash +php artisan vendor:publish +``` Now you're all set! ## Usage You can perform all methods on Adldap through its facade like so: +```php +$user = Adldap::users()->find('john doe'); - $user = Adldap::users()->find('john doe'); - - $search = Adldap::search()->where('cn', '=', 'John Doe')->get(); - - - if(Adldap::authenticate($username, $password)) - { - // Passed! - } +$search = Adldap::search()->where('cn', '=', 'John Doe')->get(); -Or you can inject the Adldap contract: - use Adldap\Contracts\Adldap; +if (Adldap::authenticate($username, $password)) { + // Passed! +} +``` + +Or you can inject the Adldap contract: +```php +use Adldap\Contracts\Adldap; + +class UserController extends Controller +{ + /** + * @var Adldap + */ + protected $adldap; + + /** + * Constructor. + * + * @param Adldap $adldap + */ + public function __construct(Adldap $adldap) + { + $this->adldap = $adldap; + } - class UserController extends Controller + /** + * Displays the all LDAP users. + * + * @return \Illuminate\View\View + */ + public function index() { - /** - * @var Adldap - */ - protected $adldap; + $users = $this->adldap->users()->all(); - /** - * Constructor. - * - * @param Adldap $adldap - */ - public function __construct(Adldap $adldap) - { - $this->adldap = $adldap; - } - - /** - * Displays the all LDAP users. - * - * @return \Illuminate\View\View - */ - public function index() - { - $users = $this->adldap->users()->all(); - - return view('users.index', compact('users')); - } + return view('users.index', compact('users')); } +} +``` To see more usage in detail, please visit the [Adldap2 Repository](http://github.com/Adldap2/Adldap2); @@ -87,29 +92,33 @@ to the users as you would a regular laravel application. ### Installation Insert the `AdldapAuthServiceProvider` into your `config/app.php` file: +```php +Adldap\Laravel\AdldapAuthServiceProvider::class, +``` - Adldap\Laravel\AdldapAuthServiceProvider::class, - Publish the auth configuration: - php artisan vendor:publish - -Change the auth driver in `config/auth.php` to `adldap`: +```bash +php artisan vendor:publish +``` - /* - |-------------------------------------------------------------------------- - | Default Authentication Driver - |-------------------------------------------------------------------------- - | - | This option controls the authentication driver that will be utilized. - | This driver manages the retrieval and authentication of the users - | attempting to get access to protected areas of your application. - | - | Supported: "database", "eloquent" - | - */ - - 'driver' => 'adldap', +Change the auth driver in `config/auth.php` to `adldap`: +```php +/* +|-------------------------------------------------------------------------- +| Default Authentication Driver +|-------------------------------------------------------------------------- +| +| This option controls the authentication driver that will be utilized. +| This driver manages the retrieval and authentication of the users +| attempting to get access to protected areas of your application. +| +| Supported: "database", "eloquent" +| +*/ + +'driver' => 'adldap', +``` ### Usage @@ -123,27 +132,31 @@ This option just allows you to set your input name to however you see fit, and a In your login form, change the username form input name to your configured input name. By default this is set to `email`: +```html + - - - - -You'll also need to add the following to your AuthController if you're not overriding the default postLogin method. + +``` - protected $username = 'email'; +You'll also need to add the following to your AuthController if you're not overriding the default postLogin method. +```php +protected $username = 'email'; +``` If you'd like to use the users `samaccountname` to login instead, just change your input name and auth configuration: +```html + - - - + +``` > **Note**: If you're using the `username` input field, make sure you have the `username` field inside your users database table as well. By default, laravel's migrations use the `email` field. Inside `config/adldap_auth.php` - - 'username_attribute' => ['username' => 'samaccountname'], +```php +'username_attribute' => ['username' => 'samaccountname'], +``` > **Note** The actual authentication is done with the `login_attribute` inside your `config/adldap_auth.php` file. @@ -171,57 +184,59 @@ attributes here, however be sure that your database table contains the key you'v Inside your `config/adldap_auth.php` file there is a configuration option named `bind_user_to_model`. Setting this to true sets the `adldapUser` property on your configured auth User model to the Adldap User model. For example: +```php +if (Auth::attempt($credentials)) { + $user = Auth::user(); - if(Auth::attempt($credentials)) - { - $user = Auth::user(); - - var_dump($user); // Returns instance of App\User; - - var_dump($user->adldapUser); // Returns instance of Adldap\Models\User; - - // Retrieving the authenticated LDAP users groups - $groups = $user->adldapUser->getGroups(); - } + var_dump($user); // Returns instance of App\User; + + var_dump($user->adldapUser); // Returns instance of Adldap\Models\User; + // Retrieving the authenticated LDAP users groups + $groups = $user->adldapUser->getGroups(); +} +``` + You **must** insert the trait `Adldap\Laravel\Traits\AdldapUserModelTrait` onto your configured auth User model, **OR** Add the public property `adldapUser` to your model. - // app/User.php - -