mirror of
https://github.com/bitinflow/accounts.git
synced 2026-03-14 14:05:52 +00:00
39 lines
912 B
PHP
39 lines
912 B
PHP
<?php
|
|
|
|
|
|
namespace Bitinflow\Accounts\Http\Middleware;
|
|
|
|
|
|
use Bitinflow\Accounts\Exceptions\MissingScopeException;
|
|
use Closure;
|
|
use Illuminate\Auth\AuthenticationException;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
|
|
class CheckForAnyScope
|
|
{
|
|
/**
|
|
* Handle the incoming request.
|
|
*
|
|
* @param Request $request
|
|
* @param Closure $next
|
|
* @param mixed ...$scopes
|
|
* @return Response
|
|
*
|
|
* @throws AuthenticationException|MissingScopeException
|
|
*/
|
|
public function handle($request, $next, ...$scopes)
|
|
{
|
|
if (!$request->user() || !$request->user()->bitinflowToken()) {
|
|
throw new AuthenticationException;
|
|
}
|
|
|
|
foreach ($scopes as $scope) {
|
|
if ($request->user()->bitinflowTokenCan($scope)) {
|
|
return $next($request);
|
|
}
|
|
}
|
|
|
|
throw new MissingScopeException($scopes);
|
|
}
|
|
} |