Skip to content

Instantly share code, notes, and snippets.

@DarkGhostHunter
Last active April 19, 2019 05:45
Show Gist options
  • Select an option

  • Save DarkGhostHunter/b4e699b8ecdfa159927dad7f76dce0ba to your computer and use it in GitHub Desktop.

Select an option

Save DarkGhostHunter/b4e699b8ecdfa159927dad7f76dce0ba to your computer and use it in GitHub Desktop.
Laravel: Understanding the Authentication Guard [Part 4] - Example 1
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
// 'App\Model' => 'App\Policies\ModelPolicy',
];
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
// Since the Auth Manager doesn't have to be called in every Request, we will just
// set a callback before the application resolves it and passes it where it was
// called. In that moment we will add the HeaderGuard and ApiUserProvider.
$this->app->resolving('auth', function ($auth) {
$auth->extend('header', function ($app, $name, array $config) {
return $app->make(\App\Auth\HeaderGuard::class, [
'name' => $name,
'config' => $config,
'provider' => $app['auth']->createUserProvider($config['provider'] ?? null)
]);
});
$auth->provider('external-api', function ($app, $config) {
return $app->make(\App\Auth\ApiUserProvider::class, [
'config' => $config,
]);
});
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment