Lumen/Laravel multiple auth providers

Hey friends, i have a lumen installation that has two groups of routes. For both groups i need a different userbase. So i thought i solve this by using a route group with a different middleware for both of them. i named them auth_a and auth_b.

In order to enable this i added the following to my app.php

$app->routeMiddleware ([
	'auth_a'    => App\Http\Middleware\AuthenticateA::class,
	'auth_b'    => App\Http\Middleware\AuthenticateB::class,
$app->register (App\Providers\AuthServiceProviderA::class);
$app->register (App\Providers\AuthServiceProviderB::class);

Both app/Http/Middleware/AuthenticateA and app/Http/Middleware/AuthenticateB have pretty much the same content. Only the class name is different. The rest is like the basic Authenticate.php provided by Lumen by default.

Then in the providers i extend the ServiceProvider class and added the empty method register () and the boot () method looks like this:

$this->app['auth']->viaRequest ('api', function ($request)
	if ($request->input('api_token'))
		print_r('I am in provider A');
		return User::where ('api_token', $request->input ('api_token'))->first ();

The only difference between my AuthServiceProviderA and AuthServiceProviderB is that the print_r is different to tell me where i am during debugging.

Now when i call both route groups always the last service controller gets called. Not the assigend one, but always the last one registered in app.php gets executed.

Can you please tell me what i am doing wrong?


Sign in to participate in this thread!

We'd like to thank these amazing companies for supporting us