mirror of
https://github.com/flarum/core.git
synced 2025-10-18 18:26:07 +02:00
Remove Middleware suffix
This commit is contained in:
29
src/Api/Middleware/LoginWithHeader.php
Normal file
29
src/Api/Middleware/LoginWithHeader.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php namespace Flarum\Api\Middleware;
|
||||
|
||||
use Flarum\Core\Models\AccessToken;
|
||||
use Flarum\Core\Support\Actor;
|
||||
use Closure;
|
||||
|
||||
class LoginWithHeader
|
||||
{
|
||||
protected $actor;
|
||||
|
||||
protected $prefix = 'Token ';
|
||||
|
||||
public function __construct(Actor $actor)
|
||||
{
|
||||
$this->actor = $actor;
|
||||
}
|
||||
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$header = $request->headers->get('authorization');
|
||||
if (starts_with($header, $this->prefix) &&
|
||||
($token = substr($header, strlen($this->prefix))) &&
|
||||
($accessToken = AccessToken::where('id', $token)->first())) {
|
||||
$this->actor->setUser($accessToken->user);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user