Opauth integrating with Auth

50 views
Skip to first unread message

Chauncey Starkey

unread,
Feb 24, 2015, 10:25:51 AM2/24/15
to opa...@googlegroups.com
I am getting a successful login with Opauth, and sending results to Auth for login, which is returning true, yet when I continue into the protected area I am notified "You are not authorized to access that location." and redirected to the login page. I'm sure I'm missing something obvious... Code follows, thanks for any help!

class User extends AppModel {
public $validate = array(
'provider' => array(
'rule' => 'notEmpty'
),
'uid' => array(
'rule' => 'notEmpty'
),
'name' => array(
'rule' => 'notEmpty'
),
'email' => array(
'rule' => 'notEmpty'
)
);
}

class AppController extends Controller {
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array(
'controller' => 'pages',
'action' => 'index'
),
'logoutRedirect' => array(
'controller' => 'users',
'action' => 'login'
)
)
);
public function beforeFilter() {
$this->Auth->allow('opauth_complete', 'logout');
}
}

public function opauth_complete() {
// Find User
$user = $this->User->find('first', array(
'conditions' => array(
'provider' => $this->data['auth']['provider'],
'uid' => $this->data['auth']['uid']
)
));
    if (empty($user)) {
// Process user for access request, notify user of approval/disapproval when processed
}
elseif (empty($user['User']['role'])) {
        // Notify user request hasn't been processed yet; don't call us, we'll call you
}
elseif ($user['User']['role'] == "Denied") {
        // Notify user they have been denied access by the administrator
}
else {
// Authorized User, Login
if ($this->Auth->login($user)) {
// Welcome user back (this is happening)
}
else {
// Notify login failed (not happening)
}
}
}
Reply all
Reply to author
Forward
0 new messages