mirror of
https://github.com/bitinflow/accounts.git
synced 2026-03-14 14:05:52 +00:00
change namespace and cleanup code
This commit is contained in:
39
src/Accounts/Http/Middleware/CheckForAnyScope.php
Normal file
39
src/Accounts/Http/Middleware/CheckForAnyScope.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user