koel/app/Providers/AuthServiceProvider.php

41 lines
1 KiB
PHP
Raw Normal View History

2015-12-13 04:42:28 +00:00
<?php
namespace App\Providers;
use App\Models\Playlist;
use App\Models\User;
use App\Policies\PlaylistPolicy;
use App\Policies\UserPolicy;
use App\Services\TokenManager;
2015-12-13 04:42:28 +00:00
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
2015-12-13 04:42:28 +00:00
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
Playlist::class => PlaylistPolicy::class,
User::class => UserPolicy::class,
2015-12-13 04:42:28 +00:00
];
/**
* Register any application authentication / authorization services.
*/
2020-12-22 20:11:22 +00:00
public function boot(): void
2015-12-13 04:42:28 +00:00
{
2016-09-26 06:30:00 +00:00
$this->registerPolicies();
Auth::viaRequest('token-via-query-parameter', static function (Request $request): ?User {
/** @var TokenManager $tokenManager */
$tokenManager = app(TokenManager::class);
return $tokenManager->getUserFromPlainTextToken($request->api_token ?: '');
});
2015-12-13 04:42:28 +00:00
}
}