Adicion de END POINTS para tokens (EXPIRE y DELETE)

This commit is contained in:
Brayan Osmar Pereyra Suxo
2014-10-28 09:17:54 -04:00
parent 2b61a2fa84
commit 19464fabb0
2 changed files with 44 additions and 0 deletions

View File

@@ -145,6 +145,24 @@ class PmPdo implements \OAuth2\Storage\AuthorizationCodeInterface,
return $stmt->execute(compact('code'));
}
public function expireToken($token)
{
$access_token = new \OauthAccessTokens();
$access_token->load($token);
$stmt = $this->db->prepare(sprintf('UPDATE %s SET EXPIRES=%s WHERE ACCESS_TOKEN=:token', $this->config['access_token_table'], "'".Date('Y-m-d H:i:s')."'"));
return $stmt->execute(compact('token'));
}
public function deleteToken($token)
{
$access_token = new \OauthAccessTokens();
$access_token->load($token);
$stmt = $this->db->prepare(sprintf('DELETE FROM %s WHERE ACCESS_TOKEN = :token', $this->config['access_token_table']));
$stmt->execute(compact('token'));
$stmt = $this->db->prepare(sprintf('DELETE FROM %s WHERE EXPIRES>%s', $this->config['refresh_token_table'], "'".Date('Y-m-d H:i:s')."'"));
return $stmt->execute(compact('token'));
}
/* OAuth2_Storage_UserCredentialsInterface */
public function checkUserCredentials($username, $password)
{

View File

@@ -73,6 +73,32 @@ class Server implements iAuthenticate
$this->server->setScopeUtil($scope);
}
/**
* @url POST /:token/expire
*
*/
public function doPostExpireToken($token)
{
try {
$this->storage->expireToken($token);
} catch (\Exception $e) {
throw new RestException(400, $e->getMessage());
}
}
/**
* @url DELETE /:token
*
*/
public function doDeleteToken($token)
{
try {
$this->storage->deleteToken($token);
} catch (\Exception $e) {
throw new RestException(400, $e->getMessage());
}
}
public static function setDatabaseSource($user, $password = '', $dsn = '')
{
if (is_array($user)) {