mirror of
https://github.com/koel/koel
synced 2024-12-26 04:23:05 +00:00
40 lines
1 KiB
PHP
40 lines
1 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\Playlist;
|
|
use App\Models\User;
|
|
use App\Policies\PlaylistPolicy;
|
|
use App\Policies\UserPolicy;
|
|
use App\Services\TokenManager;
|
|
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class AuthServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* The policy mappings for the application.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $policies = [
|
|
Playlist::class => PlaylistPolicy::class,
|
|
User::class => UserPolicy::class,
|
|
];
|
|
|
|
/**
|
|
* Register any application authentication / authorization services.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
$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 ?: '');
|
|
});
|
|
}
|
|
}
|