Adldap2 / Adldap2-Laravel

LDAP Authentication & Management for Laravel
MIT License
911 stars 184 forks source link

Usage with Lumen #643

Closed oranges13 closed 5 years ago

oranges13 commented 5 years ago

Description:

Attempting to install and connect to Active Directory / LDAP in Lumen

Steps To Reproduce:

composer require adldap2/adldap2-laravel

In bootstrap/app.php added:

$app->register(Adldap\Laravel\AdldapServiceProvider::class);
$app->register(Adldap\Laravel\AdldapAuthServiceProvider::class);

Lumen does not support vendor:publish on it's own so manually copied files to the requisite config/ location and updated the settings respectively:

cp vendor/adldap2/adldap2-laravel/src/Config/config.php config/adldap.php cp vendor/adldap2/adldap2-laravel/src/Config/auth.php config/adldap_auth.php

When visiting any route in application after enabling Adldap2 Error received: In AdldapAuthServiceProvider.php line 42: Call to a member function extend() on null

oranges13 commented 5 years ago

Anyone else having this issue, you need to uncomment

$app->withFacades(); in bootstrap/app.php

briancardonas commented 5 years ago

Hi @oranges13, I'm trying to sync users password from AD using adldap, but I have a custom Controller working with the Adldap instance; the problem is: when I call the auth()->attemp method I can't get the sync function the plugin has; I mean, the users doesn't create on the database.

My code:

MiCustomController LdapController: `<?php

namespace App\Http\Controllers;

use Adldap\Adldap; use App\Commons\MensajeDeRespuesta; use App\Maps\LdapMap; use App\Validators\LdapValidator; use Illuminate\Http\Request; use Illuminate\Http\Response; use Adldap\Models\Concerns\HasDescription;

class LdapController extends Controller {

use HasDescription;

public $instanciaLdap;
public $proveedorLdap;
public $ldapMap;

public function __construct() {
    $this->instanciaLdap = new Adldap();
    $this->instanciaLdap->addProvider(config('ldap'));
    $this->proveedorLdap = $this->instanciaLdap->connect();
    $this->ldapMap = new LdapMap();
}

public function auth(Request $request) {
    $this->validate($request, LdapValidator::camposLogin(), LdapValidator::mensajesLogin());
    if ($request->auth === 'true') {
        if ($this->instanciaLdap->auth()->attempt($request->usuario, $request->clave) === true) {
            return $this->respuestaCorrecta(MensajeDeRespuesta::USUARIO_LOGUEADO);
        } else {
            return $this->respuestaIncorrecta(MensajeDeRespuesta::CREDENCIALES_INCORRECTAS, Response::HTTP_UNPROCESSABLE_ENTITY);
        }
    } else {
        return $this->respuestaIncorrecta(MensajeDeRespuesta::PETICION_INVALIDA, Response::HTTP_UNPROCESSABLE_ENTITY);
    }
}`

I also have users migration.

My bootstrap app file: `<?php

require_once DIR.'/../vendor/autoload.php';

try { (new Dotenv\Dotenv(dirname(DIR)))->load(); } catch (Dotenv\Exception\InvalidPathException $e) { // }

/* -------------------------------------------------------------------------- Create The Application
Here we will load the environment and create the application instance
that serves as the central piece of this framework. We'll use this
application as an "IoC" container and router for this framework.

*/

$app = new Laravel\Lumen\Application( dirname(DIR) );

$app->withFacades();

$app->withEloquent();

$app->configure('adldap_auth');

$app->configure('adldap');

$app->configure('ldap');

/* -------------------------------------------------------------------------- Register Container Bindings
Now we will register a few bindings in the service container. We will
register the exception handler and the console kernel. You may add
your own bindings here if you like or you can make another file.

*/

$app->singleton( Illuminate\Contracts\Debug\ExceptionHandler::class, App\Exceptions\Handler::class );

$app->singleton( Illuminate\Contracts\Console\Kernel::class, App\Console\Kernel::class );

/* -------------------------------------------------------------------------- Register Middleware
Next, we will register the middleware with the application. These can
be global middleware that run before and after each request into a
route or middleware that'll be assigned to some specific routes.

*/

$app->middleware([ App\Http\Middleware\AuthenticateAccess::class ]);

// $app->routeMiddleware([ // 'auth' => App\Http\Middleware\Authenticate::class, // ]);

/* -------------------------------------------------------------------------- Register Service Providers
Here we will register all of the application's service providers which
are used to bind services into the container. Service providers are
totally optional, so you are not required to uncomment this line.

*/

// $app->register(App\Providers\AppServiceProvider::class); // $app->register(App\Providers\AuthServiceProvider::class); // $app->register(App\Providers\EventServiceProvider::class); $app->register(Adldap\Laravel\AdldapServiceProvider::class); $app->register(Adldap\Laravel\AdldapAuthServiceProvider::class);

/* -------------------------------------------------------------------------- Load The Application Routes
Next we will include the routes file so that they can all be added to
the application. This will provide all of the URLs the application
can respond to, as well as the controllers that may handle them.

*/

$app->router->group([ 'namespace' => 'App\Http\Controllers', ], function ($router) { require DIR.'/../routes/web.php'; });

return $app; `

and in config dir I have: adldap_auth.php and adldap.php files

Thank u for helping me