summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrent Shaffer <bshafs@gmail.com>2013-08-12 20:35:58 +0400
committerBrent Shaffer <bshafs@gmail.com>2013-08-12 20:35:58 +0400
commit7abe692c57d8f11026556036ee59575f8b0d328e (patch)
treeaafe163a6eeb5d2e8d2ce4e8c81eb6aa6938cad3 /src
parent69ba3a22a34d85697e0741c38cf9874d8e33dbe3 (diff)
downloadoauth2-server-php-1.0.tar.xz
fixes unnecessary BC breaking changes made by 69ba3a2v1.0
Diffstat (limited to 'src')
-rw-r--r--src/OAuth2/Storage/Pdo.php38
-rw-r--r--src/OAuth2/Storage/Redis.php15
-rw-r--r--src/OAuth2/Storage/UserCredentialsInterface.php6
3 files changed, 37 insertions, 22 deletions
diff --git a/src/OAuth2/Storage/Pdo.php b/src/OAuth2/Storage/Pdo.php
index bf8c9c3..49f977a 100644
--- a/src/OAuth2/Storage/Pdo.php
+++ b/src/OAuth2/Storage/Pdo.php
@@ -35,10 +35,10 @@ class Pdo implements AuthorizationCodeInterface,
}
// merge optional parameters
$connection = array_merge(array(
- 'user_id' => null,
+ 'username' => null,
'password' => null,
), $connection);
- $connection = new \PDO($connection['dsn'], $connection['user_id'], $connection['password']);
+ $connection = new \PDO($connection['dsn'], $connection['username'], $connection['password']);
}
$this->db = $connection;
@@ -151,17 +151,17 @@ class Pdo implements AuthorizationCodeInterface,
}
/* OAuth2_Storage_UserCredentialsInterface */
- public function checkUserCredentials($user_id, $password)
+ public function checkUserCredentials($username, $password)
{
- if ($user = $this->getUser($user_id)) {
+ if ($user = $this->getUser($username)) {
return $this->checkPassword($user, $password);
}
return false;
}
- public function getUserDetails($user_id)
+ public function getUserDetails($username)
{
- return $this->getUser($user_id);
+ return $this->getUser($username);
}
/* OAuth2_Storage_RefreshTokenInterface */
@@ -201,25 +201,33 @@ class Pdo implements AuthorizationCodeInterface,
return $user['password'] == sha1($password);
}
- public function getUser($user_id)
+ public function getUser($username)
{
- $stmt = $this->db->prepare($sql = sprintf('SELECT * from %s where user_id=:user_id', $this->config['user_table']));
- $stmt->execute(array('user_id' => $user_id));
- return $stmt->fetch();
+ $stmt = $this->db->prepare($sql = sprintf('SELECT * from %s where username=:username', $this->config['user_table']));
+ $stmt->execute(array('username' => $username));
+
+ if (!$userInfo = $stmt->fetch()) {
+ return false;
+ }
+
+ // the default behavior is to use "username" as the user_id
+ return array_merge(array(
+ 'user_id' => $username
+ ), $userInfo);
}
- public function setUser($user_id, $password, $firstName = null, $lastName = null)
+ public function setUser($username, $password, $firstName = null, $lastName = null)
{
// do not store in plaintext
$password = sha1($password);
// if it exists, update it.
- if ($this->getUser($user_id)) {
- $stmt = $this->db->prepare($sql = sprintf('UPDATE %s SET password=:password, first_name=:firstName, last_name=:lastName where user_id=:user_id', $this->config['user_table']));
+ if ($this->getUser($username)) {
+ $stmt = $this->db->prepare($sql = sprintf('UPDATE %s SET password=:password, first_name=:firstName, last_name=:lastName where username=:username', $this->config['user_table']));
} else {
- $stmt = $this->db->prepare(sprintf('INSERT INTO %s (user_id, password, first_name, last_name) VALUES (:user_id, :password, :firstName, :lastName)', $this->config['user_table']));
+ $stmt = $this->db->prepare(sprintf('INSERT INTO %s (username, password, first_name, last_name) VALUES (:username, :password, :firstName, :lastName)', $this->config['user_table']));
}
- return $stmt->execute(compact('user_id', 'password', 'firstName', 'lastName'));
+ return $stmt->execute(compact('username', 'password', 'firstName', 'lastName'));
}
/* OAuth2_Storage_JWTBearerInterface */
diff --git a/src/OAuth2/Storage/Redis.php b/src/OAuth2/Storage/Redis.php
index 979fb32..440c3a2 100644
--- a/src/OAuth2/Storage/Redis.php
+++ b/src/OAuth2/Storage/Redis.php
@@ -108,14 +108,21 @@ class Redis implements AuthorizationCodeInterface,
public function getUser($username)
{
- return $this->getValue($this->config['user_key'] . $username);
+ if (!$userInfo = $this->getValue($this->config['user_key'] . $username)) {
+ return false;
+ }
+
+ // the default behavior is to use "username" as the user_id
+ return array_merge(array(
+ 'user_id' => $username,
+ ), $userInfo);
}
- public function setUser($user_id, $password, $first_name = null, $last_name = null)
+ public function setUser($username, $password, $first_name = null, $last_name = null)
{
return $this->setValue(
- $this->config['user_key'] . $user_id,
- compact('user_id', 'password', 'first_name', 'last_name')
+ $this->config['user_key'] . $username,
+ compact('username', 'password', 'first_name', 'last_name')
);
}
diff --git a/src/OAuth2/Storage/UserCredentialsInterface.php b/src/OAuth2/Storage/UserCredentialsInterface.php
index 2a0f058..6e0fd7b 100644
--- a/src/OAuth2/Storage/UserCredentialsInterface.php
+++ b/src/OAuth2/Storage/UserCredentialsInterface.php
@@ -38,13 +38,13 @@ interface UserCredentialsInterface
/**
* @return
- * ARRAY the associated "scope" or "user_id" values if applicable
+ * ARRAY the associated "user_id" and optional "scope" values
* This function MUST return FALSE if the requested user does not exist or is
* invalid. "scope" is a space-separated list of restricted scopes.
* @code
* return array(
- * "scope" => SCOPE // OPTIONAL space-separated list of restricted scopes
- * "user_id" => USER_ID, // REQUIRED user id to be stored with the authorization code or access token
+ * "user_id" => USER_ID, // REQUIRED user_id to be stored with the authorization code or access token
+ * "scope" => SCOPE // OPTIONAL space-separated list of restricted scopes
* );
* @endcode
*/