Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from chadicus/fea/add-revoke
Add /revoke route
- Loading branch information
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace Chadicus\Slim\OAuth2\Routes; | ||
|
||
use Chadicus\Slim\OAuth2\Http\MessageBridge; | ||
use OAuth2; | ||
use Slim\Slim; | ||
|
||
/** | ||
* The revoke class. | ||
* | ||
*/ | ||
class Revoke | ||
{ | ||
const ROUTE = '/revoke'; | ||
|
||
/** | ||
* The slim framework application instance. | ||
* | ||
* @var Slim | ||
*/ | ||
private $slim; | ||
|
||
/** | ||
* The oauth2 server instance. | ||
* | ||
* @var OAuth2\Server | ||
*/ | ||
private $server; | ||
|
||
/** | ||
* Construct a new instance of Authorize. | ||
* | ||
* @param Slim $slim The slim framework application instance. | ||
* @param OAuth2\Server $server The oauth2 server imstance. | ||
*/ | ||
public function __construct(Slim $slim, OAuth2\Server $server) | ||
{ | ||
$this->slim = $slim; | ||
$this->server = $server; | ||
} | ||
|
||
/** | ||
* Call this class as a function. | ||
* | ||
* @return void | ||
*/ | ||
public function __invoke() | ||
{ | ||
$request = MessageBridge::newOAuth2Request($this->slim->request()); | ||
MessageBridge::mapResponse( | ||
$this->server->handleRevokeRequest($request), | ||
$this->slim->response() | ||
); | ||
} | ||
|
||
/** | ||
* Register this route with the given Slim application and OAuth2 server | ||
* | ||
* @param Slim $slim The slim framework application instance. | ||
* @param OAuth2\Server $server The oauth2 server instance. | ||
* | ||
* @return void | ||
*/ | ||
public static function register(Slim $slim, OAuth2\Server $server) | ||
{ | ||
$slim->post(self::ROUTE, new static($slim, $server))->name('revoke'); | ||
} | ||
} |