aboutsummaryrefslogtreecommitdiffhomepage
path: root/infrastructure/Auth/Middleware/AccessTokenChecker.php
diff options
context:
space:
mode:
authorMarvin Borner2018-07-20 16:34:32 +0200
committerMarvin Borner2018-07-20 16:34:32 +0200
commit74cb1477bb921a2378ea22a552b71a48c11e0931 (patch)
tree621ab17315be667c16dad8f3d5f44d67a7a47e8f /infrastructure/Auth/Middleware/AccessTokenChecker.php
parent400591b34d4b0a6288834539808a9dede8a60e3a (diff)
Better API (integrated oauth completely)
Diffstat (limited to 'infrastructure/Auth/Middleware/AccessTokenChecker.php')
-rw-r--r--infrastructure/Auth/Middleware/AccessTokenChecker.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/infrastructure/Auth/Middleware/AccessTokenChecker.php b/infrastructure/Auth/Middleware/AccessTokenChecker.php
new file mode 100644
index 0000000..f79f5cb
--- /dev/null
+++ b/infrastructure/Auth/Middleware/AccessTokenChecker.php
@@ -0,0 +1,37 @@
+<?php
+
+namespace Infrastructure\Auth\Middleware;
+
+use Closure;
+use Illuminate\Foundation\Application;
+use Illuminate\Auth\Middleware\Authenticate;
+use Illuminate\Auth\AuthenticationException;
+use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
+
+class AccessTokenChecker
+{
+ private $app;
+
+ private $oAuthMiddleware;
+
+ public function __construct(
+ Application $app,
+ Authenticate $authenticate
+ ) {
+ $this->app = $app;
+ $this->authenticate = $authenticate;
+ }
+
+ public function handle($request, Closure $next, $scopesString = null)
+ {
+ if ($this->app->environment() !== 'testing') {
+ try {
+ return $this->authenticate->handle($request, $next, 'api');
+ } catch (AuthenticationException $e) {
+ throw new UnauthorizedHttpException('Challenge');
+ }
+ }
+
+ return $next($request);
+ }
+}