Skip to content

Commit

Permalink
Merge 03ff918 into 27a0feb
Browse files Browse the repository at this point in the history
  • Loading branch information
chadicus committed Mar 15, 2018
2 parents 27a0feb + 03ff918 commit 0970499
Show file tree
Hide file tree
Showing 5 changed files with 507 additions and 13 deletions.
5 changes: 1 addition & 4 deletions .travis.yml
@@ -1,10 +1,8 @@
language: php
php:
- 5.6
- 7.0
- 7.1
- 7.2
- hhvm
- nightly
env:
- PREFER_LOWEST="--prefer-lowest --prefer-stable"
Expand All @@ -13,10 +11,9 @@ matrix:
fast_finish: true
allow_failures:
- php: 7.2
- php: hhvm
- php: nightly
before_script:
- composer update $PREFER_LOWEST
script:
- ./vendor/bin/phpunit --coverage-clover clover.xml
after_success: sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then ./vendor/bin/coveralls -v; fi'
after_success: ./vendor/bin/coveralls -v
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015-2017 Chad Gray
Copyright (c) 2015 Chad Gray

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Expand Up @@ -14,18 +14,18 @@
"sort-packages": true
},
"require": {
"php": "^5.6 || ^7.0",
"php": "^7.0",
"bshaffer/oauth2-server-php": "^1.9",
"chadicus/slim-oauth2-http": "^3.1",
"chadicus/psr-middleware": "^1.0",
"container-interop/container-interop": "^1.1",
"psr/http-message": "^1.0",
"container-interop/container-interop": "^1.1"
"psr/http-server-middleware": "^1.0"
},
"require-dev": {
"chadicus/coding-standard": "^1.3",
"php-coveralls/php-coveralls": "^1.0",
"php-di/php-di": "^5.4",
"phpunit/phpunit": "^5.7",
"phpunit/phpunit": "^6.0",
"zendframework/zend-diactoros": ">=1.3.2"
},
"autoload": {
Expand Down
41 changes: 38 additions & 3 deletions src/Authorization.php
Expand Up @@ -4,9 +4,10 @@
use ArrayAccess;
use Chadicus\Slim\OAuth2\Http\RequestBridge;
use Chadicus\Slim\OAuth2\Http\ResponseBridge;
use Chadicus\Psr\Middleware\MiddlewareInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Interop\Container\ContainerInterface;
use OAuth2;

Expand Down Expand Up @@ -65,7 +66,7 @@ public function __construct(OAuth2\Server $server, $container, array $scopes = [
}

/**
* Execute this middleware.
* Execute this middleware as a function.
*
* @param ServerRequestInterface $request The PSR7 request.
* @param ResponseInterface $response The PSR7 response.
Expand All @@ -74,12 +75,46 @@ public function __construct(OAuth2\Server $server, $container, array $scopes = [
* @return ResponseInterface
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
{
$handler = new class implements RequestHandlerInterface
{
public $next;
public $response;

/**
* Handle the request and return a response.
*
* @param ServerRequestInterface $request The request to handle.
*
* @return ResponseInterface
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
return call_user_func_array($this->next, [$request, $this->response]);
}
};

$handler->next = $next;
$handler->response = $response;

return $this->process($request, $handler);
}

/**
* Execute this middleware.
*
* @param ServerRequestInterface $request The PSR-7 request.
* @param RequestHandlerInterface $handler The PSR-15 request handler.
*
* @return ResponseInterface
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
{
$oauth2Request = RequestBridge::toOAuth2($request);
foreach ($this->scopes as $scope) {
if ($this->server->verifyResourceRequest($oauth2Request, null, $scope)) {
$this->setToken($this->server->getResourceController()->getToken());
return $next($request, $response);
return $handler->handle($request);
}
}

Expand Down

0 comments on commit 0970499

Please sign in to comment.