openstackid/app/libs/oauth2/endpoints/TokenEndpoint.php
smarcet ad1844984e Implements: blueprint openid-oauth2-implicit-client-flow
Change-Id: Iee3c9412a3f75a4aba5421e8c5f881a60b396df0
2014-01-06 18:07:55 -03:00

43 lines
1.2 KiB
PHP

<?php
namespace oauth2\endpoints;
use oauth2\exceptions\InvalidGrantTypeException;
use oauth2\exceptions\InvalidOAuth2Request;
use oauth2\IOAuth2Protocol;
use oauth2\requests\OAuth2Request;
/**
* Class TokenEndpoint
* Token Endpoint Implementation
* The token endpoint is used by the client to obtain an access token by
* presenting its authorization grant or refresh token. The token
* endpoint is used with every authorization grant except for the
* implicit grant type (since an access token is issued directly).
* http://tools.ietf.org/html/rfc6749#section-3.2
* @package oauth2\endpoints
*/
class TokenEndpoint implements IOAuth2Endpoint
{
private $protocol;
public function __construct(IOAuth2Protocol $protocol)
{
$this->protocol = $protocol;
}
public function handle(OAuth2Request $request)
{
foreach ($this->protocol->getAvailableGrants() as $key => $grant) {
if ($grant->canHandle($request)) {
$request = $grant->buildTokenRequest($request);
if (is_null($request))
throw new InvalidGrantTypeException;
return $grant->completeFlow($request);
}
}
throw new InvalidGrantTypeException;
}
}