I've followed the instructions at https://github.com/strebl/ldap-auth with a brand new laravel project and I can't seem to get it to work. I have done the following:
Added the following line to app.php
Ccovey\LdapAuth\LdapAuthServiceProvider::class
Changed the driver to LDAP in auth.php
'providers' => [
'users' => [
'driver' => 'ldap',
'model' => App\User::class,
]
],
I've also created a adladap.php file that I haven't posted here.
I have also added middleware group in order to make sure the user was authenticated.
Route::group(['middleware' => 'auth'], function () {
Route::get('/test', function(){ return "Test";});
}
However when I try to go to the test route I get the following error
InvalidArgumentException in CreatesUserProviders.php line 40:
Authentication user provider [ldap] is not defined.
I'm sure there's some simple configuration that I've been looking over but for the life of me I can't figure out what it is.
If you are trying to do adminless LDAP, this might be of interest:
laravel-simple-ldap-auth
Related
I am using backpack for laravel V4, Laravel 6, I defined roles and permissions and assigned file-manager permission and manager role to a user. When I try to use it in route middleware I get Forbidden Error 403, what I tried:
in routes/backpack/custom.php
'middleware' => ['web', config('backpack.base.middleware_key', 'admin'), 'can:file-manager']
when I use as instructed in spatie/laravel-permission documentation :
Route::group(['middleware' => ['role:manager']], function () {
//
});
I receive Target class [role] does not exist error.
I searched different places but no luck, please advise the right way to use permission manager in routes.
I ran into the same issue.
You must add the RoleMiddleware to your config, in app/Http/Kernel.php :
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
// [...]
'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class,
];
My answer is a bit late, but I hope it will help others :)
I have a problem with my Laravel project. I created an admin route group (domain.co/admin/). The root /admin/ at one point was working then i added a few more pages have updated composer, installed doctrine/dbal, and installed chart.js since then. Now for some reason the /admin/ route no longer works but all other routes work perfectly normal.
my web.php routes look like this:
Route::get('/', function () {
return view('home');
});
Auth::routes(); // tried commenting this out
Route::middleware(['web','auth','rolecheck:Super'])->prefix('admin')-
>group(function(){
Route::get('/', 'AdminController#index');
Route::get('/test', 'AdminController#index');
Route::get('/test2', 'AdminController#test');
....
});
...
There are more route groups that also work
/admin/ gives me a permission error. /admin/test/ /admin/test2/ work fine
here is the controller
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class AdminController extends Controller
{
public function index(){
echo '2';
//return view('admin.dashboard');
}
public function test(){
echo '1';
}
}
.htaccess doesnt show anything weird (default from laravel). I have also tried clearing caches.
I found nothing in the /etc/httpd conf files.
I have tired looking through all the code for the word 'admin' and can't find anything that is pointing to why its saying permission denied.
If i change the prefix to 'admins' it works so i am guessing some part of laravel is blocking the admin/ route. Where else can i look to see where its being blocked.
Check your public folder if you have 'admin' folder there, then rename it. In my case it was a reason of such a behavior.folders structure
Check the config/auth file in your laravel directory and check the guards and providers array in it default look like this.
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'admins' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
],
Copy/Paste these files (.htaccess, index.php, favicon.ico, robots.txt) from the /public folder to the /public/admin folder.
Edit the /public/admin/index.php file and add "/.." to all 3 required php files:
from
require __DIR__.'/../vendor/autoload.php';
to
require __DIR__.'/../../vendor/autoload.php';
I am creating a package which uses API calls which I need to protect with auth middleware. I am looking at using Laravel Passport to accomplish this.
I am developing this as a package, ergo, I want to keep everything as unobtrusive as possible from the primary Laravel installation.
The issue I'm facing is in setting the relevant configuration files. Namely, in config/auth.php I need to set
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport', // change "token" -> "passport"
'provider' => 'users',
],
],
Now, how can I do this in a way that will only apply to my package?
Thanks.
If you want your package to use a different set of configurations, independent of what the installation might have defined, you could temporarily change the configuration before making your calls. In this case I'd wrap it up in a reusable class method:
use Config;
class ApiCalls {
public static function usingPackageConfig(callable $callback)
{
// Fetch original config.
$originalDriver = Config::get('auth.api.driver');
// Set custom config.
Config::set('auth.api.driver', 'passport');
// Execute callback with custom config.
$result = $callback();
// Reset config.
Config::set('auth.api.driver', $originalDriver);
return $result;
}
}
You could then call it like this:
ApiCalls::usingPackageConfig(function() {
// Make your Passport call here and it will use your package's configuration.
});
I am in charge of creating a new laravel project where the authentication is made by our LDAP. I am pretty new to laravel so excuse me for my lack of comprehension
I am trying to use this library : Adldap2-Laravel
I followed this documentation to build the authentification from scratch.
So my config/app.php have those lines added
//In providers array
Adldap\Laravel\AdldapServiceProvider::class,
Adldap\Laravel\AdldapAuthServiceProvider::class,
//In aliases
'Adldap' => Adldap\Laravel\Facades\Adldap::class,
And my config/auth.php (I also tried to only use the adldap driver, without success)
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'users' => [
'driver' => 'adldap',
'model' => App\User::class,
],
],
Everything looks right. But I can not auth, I have this error : These credentials do not match our records.
When I use this code
use Adldap\Laravel\Facades\Adldap;
$username = "myUser";
$password = "myPassword";
if (Adldap::auth()->attempt($username, $password)) {
//Queries here
}
else
{
echo "Auth failed";
}
I CAN perform queries, and the authentication works with all my users. But I can not use properly the login form behind the "Login" button.
Did I miss something ?
I do not know if the authentication should work directly without importing anything but I also tried to run this command
php artisan adldap:import
All my users are found and inserted in the laravel DB. But the authentication still does not work.
I deleted the ADLDAP_ACCOUNT_SUFFIX= from my .env file
And added the suffix directly in ADLDAP_ADMIN_USERNAME=Administrator#mycompany.something
Now I'm able to connect via the email address.
I do not know if it is the best solution but at least it works.
I let this post open for a few days to see if someone have a better idea
Just can't get the Lumen authentication to work at all.
I have a fresh install and trying to follow the docs here:
https://lumen.laravel.com/docs/5.2/authentication
I've Uncommented the AuthProvider line in the app.php file (along with everything else, facade, etc). Then in a simple controller I just do dd(Auth::use()).
I just can't get around this error:
Undefined index: provider
in AuthManager.php line 152
at Application->Laravel\Lumen\Concerns\{closure}('8', 'Undefined index: provider', '/home/vagrant/Code/gryd/api.gryd.com/vendor/illuminate/auth/AuthManager.php', '152', array('name' => 'api', 'config' => array('driver' => 'token'))) in AuthManager.php line 152
Any ideas?
EDIT:
Since someone asked for a code sample.
Install Lumen
Uncomment everything in app.php
Put this in routes:
$app->get('/api/v1/users/{id}', function () {
dd(\Auth::user());
});
This is what I've got so far, which is working but not quite how I'd like it. The following works for Token-based auth, which is the default setting in Lumen.
Enable Authentication
Register routeMiddleware and AuthServiceProvider by un-commenting the following lines in bootstrap/app.php.
$app->routeMiddleware([
'auth' => App\Http\Middleware\Authenticate::class,
]);
and
$app->register(App\Providers\AuthServiceProvider::class);
Configuration
Copy vendor/laravel/lumen-framework/config/auth.php to config/auth.php. Create the root config folder if you have to.
Inside we will find four items (defaults, guards, providers, passwords). We're concerned with the first three.
First we name the default guard as ABC.
'defaults' => [
'guard' => env('AUTH_GUARD', 'ABC'),
],
Next we define the ABC guard with token as its driver and XYZ as its provider.
'guards' => [
'ABC' => [
'driver' => 'token',
'provider' => 'XYZ'
],
],
And the XYZ provider is defined with eloquent as the driver and App\User::class as the model.
'providers' => [
'XYZ' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
],
Completing Setup
Finally, we use the auth middleware in our routing setup, as usual.
$app->group(['middleware' => 'auth'], function () use ($app) {
So this is what gets the token auth up and running. It uses the api_token field in the users table to authenticate, which can be found in TokenGuard.
I still haven't found out what effect AuthServiceProvider and $this->app['auth']->viaRequest('api', function ($request) { have on my app yet.
Well I still haven't found out how to change the api request type via .env. But for now switching it to token seems to work.
Changed Auth::viaRequest('api', functi to Auth::viaRequest('token', funct.