mirror of
https://github.com/anikeen-com/id.git
synced 2026-11-04 22:59:41 +00:00
first commit
This commit is contained in:
47 files changed
+2723
No files matched your search
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Anikeen\Id\Http\Middleware;
|
||||
|
||||
use Anikeen\Id\Exceptions\MissingScopeException;
|
||||
use Closure;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class CheckScopes
|
||||
{
|
||||
/**
|
||||
* Handle the incoming request.
|
||||
*
|
||||
* @throws AuthenticationException|MissingScopeException
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, ...$scopes): Response
|
||||
{
|
||||
if (!$request->user() || !$request->user()->anikeenToken()) {
|
||||
throw new AuthenticationException;
|
||||
}
|
||||
|
||||
foreach ($scopes as $scope) {
|
||||
if (!$request->user()->anikeenTokenCan($scope)) {
|
||||
throw new MissingScopeException($scope);
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user