Permalink
Browse files

Working on the cake adapter

  • Loading branch information...
1 parent 3d84231 commit f2ba4893fe176383ba1127e37ad3c27365c006f4 @burzum burzum committed Mar 8, 2012
Showing with 47 additions and 8 deletions.
  1. +5 −0 Controller/ClientsController.php
  2. +14 −1 Controller/ServerController.php
  3. +28 −7 Lib/Oauth2/OAuth2StorageCake.php
@@ -40,6 +40,11 @@ public function admin_add() {
}
}
+/**
+ * Adds a new client
+ *
+ * @return void
+ */
public function add() {
try {
if ($this->Oauth2Client->add($this->request->data)) {
@@ -26,6 +26,7 @@ public function beforeFilter() {
if (isset($this->Auth)) {
$this->Auth->allow('*');
}
+ $this->Components->disable('Security');
}
/**
@@ -37,6 +38,7 @@ public function authorize() {
// Clickjacking prevention (supported by IE8+, FF3.6.9+, Opera10.5+, Safari4+, Chrome 4.1.249.1042+)
header('X-Frame-Options: DENY');
+ /*
if ($this->request->is('post')) {
$userId = 42;
$this->Oauth2->finishClientAuthorization(($this->request->data["accept"] == "Yep"), $userId, $this->request->data);
@@ -49,7 +51,18 @@ public function authorize() {
$oauthError->sendHttpResponse();
$this->_stop();
}
-
+ */
+ if (isset($this->request->data['grant_type'])) {
+ switch ($this->request->data) {
+ case:
+
+ break;
+ default:
+ $this->checkUserCredentials
+ break;
+ }
+ }
+ //die(debug($this->request->data));
}
/**
@@ -3,6 +3,7 @@
require_once($basePath . 'Oauth2.php');
require_once($basePath . 'IOAuth2Storage.php');
require_once($basePath . 'IOAuth2GrantCode.php');
+require_once($basePath . 'IOAuth2GrantUser.php');
require_once($basePath . 'IOAuth2RefreshTokens.php');
/**
@@ -64,6 +65,29 @@ public function addClient($client_id, $client_secret, $redirect_uri) {
'redirect_uri' => $redirect_uri)));
}
+/**
+ * Implements IOAuth2Storage::checkClientCredentials().
+ *
+ */
+ public function checkUserCredentials($client_id, $username, $password) {
+ $result = $this->Client->find('first', array(
+ 'contain' => array(),
+ 'conditions' => array(
+ $this->Client->alias . '.' . $this->primaryKey => $client_id),
+ 'fields' => array($this->Client->alias . '.secret')));
+
+ $user = $this->User->find('first', array(
+ 'contain' => array(),
+ 'conditions' => array(
+ 'username' => $username,
+ 'password' => Security::hash($password, 'sha1', true))));
+
+ if (empty($result)) {
+ return false;
+ }
+ return true;
+ }
+
/**
* Implements IOAuth2Storage::checkClientCredentials().
*
@@ -177,15 +201,12 @@ public function checkRestrictedGrantType($client_id, $grant_type) {
*/
protected function setToken($token, $client_id, $user_id, $expires, $scope, $isRefresh = TRUE) {
$model = 'Token';
- if ($isRefresh) {
+ if ($isRefresh == true) {
$model = 'RefreshToken';
- $refresh_token = $token;
- } else {
- $oauth_token = $token;
}
$this->{$model}->save(array(
- $this->{$model}->alias => compact('refresh_token', 'oauth_token', 'client_id', 'user_id', 'expires',
+ $this->{$model}->alias => compact('token', 'client_id', 'user_id', 'expires',
'scope')));
}
@@ -207,7 +228,7 @@ protected function getToken($token, $isRefresh = true) {
if (empty($result)) {
return null;
}
- return $result[$this->{$model}->alias];
+ return $result[$this->AuthCode->alias];
}
/**
@@ -230,5 +251,5 @@ protected function hash($client_secret, $client_id) {
*/
protected function checkPassword($try, $client_secret, $client_id) {
return $try == $this->hash($client_secret, $client_id);
- }
+ }
}

0 comments on commit f2ba489

Please sign in to comment.