summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrent Shaffer <bshafs@gmail.com>2012-10-10 20:35:42 +0400
committerBrent Shaffer <bshafs@gmail.com>2012-10-10 20:35:42 +0400
commitd64bc79dbfee776db37fa162f49f7a0a847423d9 (patch)
treea68145f8480c6a2a1e33ea63fcf9ce18c9236b9e /src
parent278efc365a46c7ec0f321f35680339fa3927797a (diff)
downloadoauth2-server-php-d64bc79dbfee776db37fa162f49f7a0a847423d9.tar.xz
adds support for authorization codes in PDO storage, adds tests for this
Diffstat (limited to 'src')
-rw-r--r--src/OAuth2/Server.php2
-rw-r--r--src/OAuth2/Storage/AccessTokenInterface.php2
-rw-r--r--src/OAuth2/Storage/AuthorizationCodeInterface.php2
-rw-r--r--src/OAuth2/Storage/Memory.php4
-rw-r--r--src/OAuth2/Storage/Pdo.php28
-rw-r--r--src/OAuth2/Storage/RefreshTokenInterface.php2
6 files changed, 31 insertions, 9 deletions
diff --git a/src/OAuth2/Server.php b/src/OAuth2/Server.php
index a5380ce..b1cc4f9 100644
--- a/src/OAuth2/Server.php
+++ b/src/OAuth2/Server.php
@@ -396,7 +396,7 @@ class OAuth2_Server implements OAuth2_Response_ProviderInterface
}
if ($response_type == self::RESPONSE_TYPE_AUTHORIZATION_CODE) {
if (!isset($this->grantTypes['code'])) {
- $this->response = new OAuth2_Response_Redirect($redirect_uri, 302, 'unsupported_response_type', 'authorization code response type not supported', $state);
+ $this->response = new OAuth2_Response_Redirect($redirect_uri, 302, 'unsupported_response_type', 'authorization code grant type not supported', $state);
return false;
}
if ($this->grantTypes['code']->enforceRedirect() && !$redirect_uri) {
diff --git a/src/OAuth2/Storage/AccessTokenInterface.php b/src/OAuth2/Storage/AccessTokenInterface.php
index 1fdd59d..df3120e 100644
--- a/src/OAuth2/Storage/AccessTokenInterface.php
+++ b/src/OAuth2/Storage/AccessTokenInterface.php
@@ -44,5 +44,5 @@ interface OAuth2_Storage_AccessTokenInterface
*
* @ingroup oauth2_section_4
*/
- public function setAccessToken($oauth_token, $client_id, $user_id, $expires, $scope = NULL);
+ public function setAccessToken($oauth_token, $client_id, $user_id, $expires, $scope = null);
} \ No newline at end of file
diff --git a/src/OAuth2/Storage/AuthorizationCodeInterface.php b/src/OAuth2/Storage/AuthorizationCodeInterface.php
index ab22fe9..4a90946 100644
--- a/src/OAuth2/Storage/AuthorizationCodeInterface.php
+++ b/src/OAuth2/Storage/AuthorizationCodeInterface.php
@@ -67,6 +67,6 @@ interface OAuth2_Storage_AuthorizationCodeInterface
*
* @ingroup oauth2_section_4
*/
- public function setAuthorizationCode($code, $client_id, $user_id, $redirect_uri, $expires, $scope = NULL);
+ public function setAuthorizationCode($code, $client_id, $user_id, $redirect_uri, $expires, $scope = null);
} \ No newline at end of file
diff --git a/src/OAuth2/Storage/Memory.php b/src/OAuth2/Storage/Memory.php
index 93034d2..c986076 100644
--- a/src/OAuth2/Storage/Memory.php
+++ b/src/OAuth2/Storage/Memory.php
@@ -40,7 +40,7 @@ class OAuth2_Storage_Memory implements OAuth2_Storage_AuthorizationCodeInterface
return null;
}
- public function setAuthorizationCode($code, $client_id, $user_id, $redirect_uri, $expires, $scope = NULL)
+ public function setAuthorizationCode($code, $client_id, $user_id, $redirect_uri, $expires, $scope = null)
{
$this->authorizationCodes[$code] = compact('code', 'client_id', 'user_id', 'redirect_uri', 'expires', 'scope');
}
@@ -118,7 +118,7 @@ class OAuth2_Storage_Memory implements OAuth2_Storage_AuthorizationCodeInterface
return isset($this->accessTokens[$access_token]) ? $this->accessTokens[$access_token] : null;
}
- public function setAccessToken($access_token, $client_id, $user_id, $expires, $scope = NULL)
+ public function setAccessToken($access_token, $client_id, $user_id, $expires, $scope = null)
{
$this->accessTokens[$access_token] = compact('access_token', 'client_id', 'user_id', 'expires', 'scope');
}
diff --git a/src/OAuth2/Storage/Pdo.php b/src/OAuth2/Storage/Pdo.php
index 8690b45..99afd35 100644
--- a/src/OAuth2/Storage/Pdo.php
+++ b/src/OAuth2/Storage/Pdo.php
@@ -3,7 +3,8 @@
/**
*
*/
-class OAuth2_Storage_Pdo implements OAuth2_Storage_AccessTokenInterface, OAuth2_Storage_ClientCredentialsInterface
+class OAuth2_Storage_Pdo implements OAuth2_Storage_AuthorizationCodeInterface,
+ OAuth2_Storage_AccessTokenInterface, OAuth2_Storage_ClientCredentialsInterface
{
private $db;
private $config;
@@ -32,6 +33,7 @@ class OAuth2_Storage_Pdo implements OAuth2_Storage_AccessTokenInterface, OAuth2_
$this->config = array_merge(array(
'client_table_name' => 'oauth_clients',
'token_table_name' => 'oauth_access_tokens',
+ 'code_table_name' => 'oauth_authorization_codes',
), $config);
}
@@ -74,14 +76,34 @@ class OAuth2_Storage_Pdo implements OAuth2_Storage_AccessTokenInterface, OAuth2_
return $stmt->fetch();
}
- public function setAccessToken($access_token, $client_id, $user_id, $expires, $scope = NULL)
+ public function setAccessToken($access_token, $client_id, $user_id, $expires, $scope = null)
{
// if it exists, update it.
if ($this->getAccessToken($access_token)) {
$stmt = $this->db->prepare(sprintf('UPDATE %s SET client_id=:client_id, expires=:expires, user_id=:user_id, scope=:scope where access_token=:access_token', $this->config['token_table_name']));
} else {
- $stmt = $this->db->prepare(sprintf('INSERT INTO %s (client_id, expires, user_id, scope, access_token) VALUES (:client_id, :expires, :user_id, :scope, :access_token)', $this->config['token_table_name']));
+ $stmt = $this->db->prepare(sprintf('INSERT INTO %s (access_token, client_id, expires, user_id, scope) VALUES (:access_token, :client_id, :expires, :user_id, :scope)', $this->config['token_table_name']));
}
return $stmt->execute(compact('access_token', 'client_id', 'user_id', 'expires', 'scope'));
}
+
+ /* AuthorizationCodeInterface */
+ public function getAuthorizationCode($code)
+ {
+ $stmt = $this->db->prepare(sprintf('SELECT * from %s where authorization_code = "%s"', $this->config['code_table_name'], $code));
+ $stmt->execute();
+
+ return $stmt->fetch();
+ }
+
+ public function setAuthorizationCode($code, $client_id, $user_id, $redirect_uri, $expires, $scope = null)
+ {
+ // if it exists, update it.
+ if ($this->getAuthorizationCode($code)) {
+ $stmt = $this->db->prepare($sql = sprintf('UPDATE %s SET client_id=:client_id, user_id=:user_id, redirect_uri=:redirect_uri, expires=:expires, scope=:scope where authorization_code=:code', $this->config['code_table_name']));
+ } else {
+ $stmt = $this->db->prepare(sprintf('INSERT INTO %s (authorization_code, client_id, user_id, redirect_uri, expires, scope) VALUES (:code, :client_id, :user_id, :redirect_uri, :expires, :scope)', $this->config['code_table_name']));
+ }
+ return $stmt->execute(compact('code', 'client_id', 'user_id', 'redirect_uri', 'expires', 'scope'));
+ }
} \ No newline at end of file
diff --git a/src/OAuth2/Storage/RefreshTokenInterface.php b/src/OAuth2/Storage/RefreshTokenInterface.php
index 31986b3..d1a32f7 100644
--- a/src/OAuth2/Storage/RefreshTokenInterface.php
+++ b/src/OAuth2/Storage/RefreshTokenInterface.php
@@ -56,7 +56,7 @@ interface OAuth2_Storage_RefreshTokenInterface
*
* @ingroup oauth2_section_6
*/
- public function setRefreshToken($refresh_token, $client_id, $user_id, $expires, $scope = NULL);
+ public function setRefreshToken($refresh_token, $client_id, $user_id, $expires, $scope = null);
/**
* Expire a used refresh token.