Permalink
Browse files

Abstract Authentication via configuration and override option.

  • Loading branch information...
1 parent cc4fd0c commit 8ef36eecee077351bace1ca2ab24aaf70ab533c9 @mikesmullin committed Aug 19, 2011
Showing with 17 additions and 6 deletions.
  1. +2 −1 config/config.php
  2. +3 −2 libs/o_auth2_lib.php
  3. +12 −3 o_auth2_server_app_controller.php
View
@@ -6,9 +6,10 @@
'refresh_token_lifetime' => 60*60*24*7*2, // 2 weeks
'Auth' => array(
+ 'className' => 'Auth',
'fields' => array(
'username' => 'email',
'password' => 'password'
)
- ),
+ )
);
View
@@ -212,14 +212,15 @@ protected function store_auth_code($code, $client_id, $redirect_uri, $expires, $
* Required for USER_CREDENTIALS_GRANT_TYPE
*/
public function check_user_credentials($client_id, $username, $password) {
+ $Auth = Configure::read('OAuth2Server.Auth.className');
return (boolean)
!empty($username)
&& !empty($password)
// use CakePHP Auth Component to validate user credentials
- && $this->controller->Auth->identify(array(
+ && $this->controller->$Auth->identify(array(
Configure::read('OAuth2Server.Auth.fields.username') => $username,
- Configure::read('OAuth2Server.Auth.fields.password') => Security::hash($password, null, true)
+ Configure::read('OAuth2Server.Auth.fields.password') => $Auth == 'Auth'? Security::hash($password, null, true) : $password // only hash password for AuthComponent
));
}
@@ -4,15 +4,24 @@
Configure::load('OAuth2Server.config');
class OAuth2ServerAppController extends AppController {
- var $components = array('OAuth2', 'Auth');
+ var $components = array('OAuth2');
var $helpers = array();
+ /**
+ * Dynamically set Auth component.
+ */
+ function __construct() {
+ parent::__construct();
+ $this->components[] = Configure::read('OAuth2Server.Auth.className');
+ }
+
/**
* beforeFilter() callback.
* Configure Auth component.
*/
function beforeFilter() {
- $this->Auth->deny('*');
+ $Auth = Configure::read('OAuth2Server.Auth.className');
+ $this->$Auth->deny('*');
foreach (array_merge(array(
'loginAction' => array(
@@ -25,7 +34,7 @@ function beforeFilter() {
'authorize' => 'controller',
'allowedActions' => array('login', 'authorize', 'access_token')
), Configure::read('OAuth2Server.Auth')) as $k => $v) {
- $this->Auth->{$k} = $v;
+ $this->$Auth->{$k} = $v;
}
return parent::beforeFilter(); // bubble up

0 comments on commit 8ef36ee

Please sign in to comment.