Generalized access token format

This commit is contained in:
Lukáš Unger 2018-03-15 14:27:37 +01:00
parent 35c6f28aef
commit fd72d79ad3
No known key found for this signature in database
GPG Key ID: 48E84B8B7A223C26
5 changed files with 25 additions and 6 deletions

View File

@ -22,4 +22,13 @@ interface AccessTokenEntityInterface extends TokenInterface
* @return Token
*/
public function convertToJWT(CryptKey $privateKey);
/**
* Generate a string representation from the access token
*
* @param CryptKey $privateKey
*
* @return string
*/
public function getResponseString(CryptKey $privateKey);
}

View File

@ -40,6 +40,18 @@ trait AccessTokenTrait
->getToken();
}
/**
* Generate a string representation from the access token
*
* @param CryptKey $privateKey
*
* @return string
*/
public function getResponseString(CryptKey $privateKey)
{
return (string) $this->convertToJWT($privateKey);
}
/**
* @return ClientEntityInterface
*/

View File

@ -216,7 +216,7 @@ class ImplicitGrant extends AbstractAuthorizeGrant
$this->makeRedirectUri(
$finalRedirectUri,
[
'access_token' => (string) $accessToken->convertToJWT($this->privateKey),
'access_token' => $accessToken->getResponseString($this->privateKey),
'token_type' => 'Bearer',
'expires_in' => $accessToken->getExpiryDateTime()->getTimestamp() - (new \DateTime())->getTimestamp(),
'state' => $authorizationRequest->getState(),

View File

@ -24,12 +24,10 @@ class BearerTokenResponse extends AbstractResponseType
{
$expireDateTime = $this->accessToken->getExpiryDateTime()->getTimestamp();
$jwtAccessToken = $this->accessToken->convertToJWT($this->privateKey);
$responseParams = [
'token_type' => 'Bearer',
'expires_in' => $expireDateTime - (new \DateTime())->getTimestamp(),
'access_token' => (string) $jwtAccessToken,
'access_token' => $this->accessToken->getResponseString($this->privateKey),
];
if ($this->refreshToken instanceof RefreshTokenEntityInterface) {

View File

@ -30,7 +30,7 @@ class ResourceServerMiddlewareTest extends TestCase
$accessToken->setExpiryDateTime((new \DateTime())->add(new \DateInterval('PT1H')));
$accessToken->setClient($client);
$token = $accessToken->convertToJWT(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
$token = $accessToken->getResponseString(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
$request = new ServerRequest();
$request = $request->withHeader('authorization', sprintf('Bearer %s', $token));
@ -65,7 +65,7 @@ class ResourceServerMiddlewareTest extends TestCase
$accessToken->setExpiryDateTime((new \DateTime())->sub(new \DateInterval('PT1H')));
$accessToken->setClient($client);
$token = $accessToken->convertToJWT(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
$token = $accessToken->getResponseString(new CryptKey('file://' . __DIR__ . '/../Stubs/private.key'));
$request = new ServerRequest();
$request = $request->withHeader('authorization', sprintf('Bearer %s', $token));