Changeset View
Changeset View
Standalone View
Standalone View
src/app/Providers/AuthServiceProvider.php
<?php | <?php | ||||
namespace App\Providers; | namespace App\Providers; | ||||
use App\Auth\LDAPUserProvider; | |||||
use Illuminate\Support\Facades\Auth; | use Illuminate\Support\Facades\Auth; | ||||
use Illuminate\Support\Facades\Gate; | use Illuminate\Support\Facades\Route; | ||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; | use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; | ||||
use Laravel\Passport\Passport; | use Laravel\Passport\Passport; | ||||
class AuthServiceProvider extends ServiceProvider | class AuthServiceProvider extends ServiceProvider | ||||
{ | { | ||||
/** | /** | ||||
* The policy mappings for the application. | * The policy mappings for the application. | ||||
* | * | ||||
* @var array | * @var array<class-string, class-string> | ||||
*/ | */ | ||||
protected $policies = [ | protected $policies = [ | ||||
// 'App\Model' => 'App\Policies\ModelPolicy', | // 'App\Model' => 'App\Policies\ModelPolicy', | ||||
]; | ]; | ||||
/** | /** | ||||
* Register any authentication / authorization services. | * Register any authentication / authorization services. | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function boot() | public function boot() | ||||
{ | { | ||||
$this->registerPolicies(); | $this->registerPolicies(); | ||||
Auth::provider( | |||||
'ldap', | |||||
function ($app, array $config) { | |||||
return new LDAPUserProvider($app['hash'], $config['model']); | |||||
} | |||||
); | |||||
// Hashes all secrets and thus makes them non-recoverable | // Hashes all secrets and thus makes them non-recoverable | ||||
/* Passport::hashClientSecrets(); */ | /* Passport::hashClientSecrets(); */ | ||||
// Only enable routes for access tokens | // Only enable routes for access tokens | ||||
Passport::routes( | Passport::routes( | ||||
function ($router) { | function ($router) { | ||||
$router->forAccessTokens(); | $router->forAccessTokens(); | ||||
// Override the default route to avoid rate-limiting. | // Override the default route to avoid rate-limiting. | ||||
\Route::post('/token', [ | Route::post('/token', [ | ||||
'uses' => 'AccessTokenController@issueToken', | 'uses' => 'AccessTokenController@issueToken', | ||||
'as' => 'passport.token', | 'as' => 'passport.token', | ||||
]); | ]); | ||||
} | } | ||||
); | ); | ||||
Passport::tokensExpireIn(now()->addMinutes(\config('auth.token_expiry_minutes'))); | Passport::tokensExpireIn(now()->addMinutes(\config('auth.token_expiry_minutes'))); | ||||
Passport::refreshTokensExpireIn(now()->addMinutes(\config('auth.refresh_token_expiry_minutes'))); | Passport::refreshTokensExpireIn(now()->addMinutes(\config('auth.refresh_token_expiry_minutes'))); | ||||
Passport::personalAccessTokensExpireIn(now()->addMonths(6)); | Passport::personalAccessTokensExpireIn(now()->addMonths(6)); | ||||
} | } | ||||
} | } |