Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Abstract Authentication via configuration and override option.

  • Loading branch information...
commit 8ef36eecee077351bace1ca2ab24aaf70ab533c9 1 parent cc4fd0c
Mike Smullin authored August 19, 2011
3  config/config.php
@@ -6,9 +6,10 @@
6 6
 	'refresh_token_lifetime'	=> 60*60*24*7*2, // 2 weeks
7 7
 
8 8
 	'Auth' => array(
  9
+		'className' => 'Auth',
9 10
 		'fields' => array(
10 11
 			'username' => 'email',
11 12
 			'password' => 'password'
12 13
 		)
13  
-	),
  14
+	)
14 15
 );
5  libs/o_auth2_lib.php
@@ -212,14 +212,15 @@ protected function store_auth_code($code, $client_id, $redirect_uri, $expires, $
212 212
 	 * Required for USER_CREDENTIALS_GRANT_TYPE
213 213
 	 */
214 214
 	public function check_user_credentials($client_id, $username, $password) {
  215
+		$Auth = Configure::read('OAuth2Server.Auth.className');
215 216
 		return (boolean)
216 217
 			   !empty($username)
217 218
 			&& !empty($password)
218 219
 
219 220
 			// use CakePHP Auth Component to validate user credentials
220  
-			&& $this->controller->Auth->identify(array(
  221
+			&& $this->controller->$Auth->identify(array(
221 222
 			  Configure::read('OAuth2Server.Auth.fields.username') => $username,
222  
-			  Configure::read('OAuth2Server.Auth.fields.password') => Security::hash($password, null, true)
  223
+			  Configure::read('OAuth2Server.Auth.fields.password') => $Auth == 'Auth'? Security::hash($password, null, true) : $password // only hash password for AuthComponent
223 224
 			));
224 225
 	}
225 226
 
15  o_auth2_server_app_controller.php
@@ -4,15 +4,24 @@
4 4
 Configure::load('OAuth2Server.config');
5 5
 
6 6
 class OAuth2ServerAppController extends AppController {
7  
-	var $components = array('OAuth2', 'Auth');
  7
+	var $components = array('OAuth2');
8 8
 	var $helpers = array();
9 9
 
10 10
 	/**
  11
+	 * Dynamically set Auth component.
  12
+	 */
  13
+	function __construct() {
  14
+		parent::__construct();
  15
+		$this->components[] = Configure::read('OAuth2Server.Auth.className');
  16
+	}
  17
+
  18
+	/**
11 19
 	 * beforeFilter() callback.
12 20
 	 * Configure Auth component.
13 21
 	 */
14 22
 	function beforeFilter() {
15  
-		$this->Auth->deny('*');
  23
+		$Auth = Configure::read('OAuth2Server.Auth.className');
  24
+		$this->$Auth->deny('*');
16 25
 
17 26
 		foreach (array_merge(array(
18 27
 			'loginAction' => array(
@@ -25,7 +34,7 @@ function beforeFilter() {
25 34
 			'authorize' => 'controller',
26 35
 			'allowedActions' => array('login', 'authorize', 'access_token')
27 36
 		), Configure::read('OAuth2Server.Auth')) as $k => $v) {
28  
-			$this->Auth->{$k} = $v;
  37
+			$this->$Auth->{$k} = $v;
29 38
 		}
30 39
 
31 40
 		return parent::beforeFilter(); // bubble up

0 notes on commit 8ef36ee

Please sign in to comment.
Something went wrong with that request. Please try again.