Addititonal refresh token validation

This commit is contained in:
Alex Bilbie 2016-01-13 00:38:23 +00:00
parent c1d15aa15c
commit 936b8f93ec

View File

@ -124,10 +124,14 @@ class RefreshTokenGrant extends AbstractGrant
} }
$validation = new ValidationData(); $validation = new ValidationData();
$validation->setAudience($client->getIdentifier()); $validation->setAudience($client->getIdentifier()); // Validates refresh token hasn't expired
$validation->setCurrentTime(time()); $validation->setCurrentTime(time()); // Validates token hasn't expired
if ($oldRefreshToken->validate($validation) === false) { if ($oldRefreshToken->validate($validation) === false) {
throw OAuthServerException::invalidRefreshToken(); throw OAuthServerException::invalidRefreshToken('Token has expired or is not linked to client');
}
if ($oldRefreshToken->getClaim('type') !== 'refreshToken') {
throw OAuthServerException::invalidRefreshToken('Token is not a refresh token');
} }
// Get the scopes for the original session // Get the scopes for the original session
@ -159,7 +163,7 @@ class RefreshTokenGrant extends AbstractGrant
$accessToken->setIdentifier(SecureKey::generate()); $accessToken->setIdentifier(SecureKey::generate());
$accessToken->setExpiryDateTime((new \DateTime())->add($tokenTTL)); $accessToken->setExpiryDateTime((new \DateTime())->add($tokenTTL));
$accessToken->setClient($client); $accessToken->setClient($client);
$accessToken->setUserIdentifier($oldRefreshToken->getClaim('uid')); $accessToken->setUserIdentifier($oldRefreshToken->getClaim('sub'));
foreach ($newScopes as $scope) { foreach ($newScopes as $scope) {
$accessToken->addScope($scope); $accessToken->addScope($scope);
} }