Last active
November 8, 2019 21:05
-
-
Save eminetto/26a2e40f63fb4f1c7546 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace RestBeer; | |
use Zend\Stratigility\MiddlewareInterface; | |
use Psr\Http\Message\ServerRequestInterface as Request; | |
use Psr\Http\Message\ResponseInterface as Response; | |
class Auth implements MiddlewareInterface | |
{ | |
public function __invoke(Request $request, Response $response, callable $out = null) | |
{ | |
if(! $request->hasHeader('authorization')){ | |
return $response->withStatus(401); | |
} | |
if (!$this->isValid($request)) { | |
return $response->withStatus(403); | |
} | |
return $out($request, $response); | |
} | |
private function isValid(Request $request) | |
{ | |
$token = $request->getHeader('authorization'); | |
//@TODO: validate token | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment