Skip to content

Commit

Permalink
Adding a couple methods to AuthComponent that are handy for doing meta
Browse files Browse the repository at this point in the history
programming on the authorization flow
  • Loading branch information
lorenzo committed Jun 5, 2014
1 parent 6e96a97 commit bbf7575
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/Controller/Component/AuthComponent.php
Expand Up @@ -220,6 +220,23 @@ class AuthComponent extends Component {
*/
protected $_methods = array();

/**
* The instance of the Authenticate provider that was used for
* successfully logging in the current user after calling `login()`
* in the same request
*
* @var Cake\Auth\BaseAuthenticate
*/
protected $_authenticateProvider;

/**
* The instance of the Authorize provider that was used to grant
* access to the current user to the url they are requesting.
*
* @var Cake\Auth\BaseAuthorize
*/
protected $_authorizationProvider;

/**
* Initializes AuthComponent for use in the controller.
*
Expand Down Expand Up @@ -455,6 +472,7 @@ public function isAuthorized($user = null, Request $request = null) {
}
foreach ($this->_authorizeObjects as $authorizer) {
if ($authorizer->authorize($user, $request) === true) {
$this->_authorizationProvider = $authorizer;
return true;
}
}
Expand Down Expand Up @@ -722,6 +740,7 @@ public function identify(Request $request, Response $response) {
foreach ($this->_authenticateObjects as $auth) {
$result = $auth->authenticate($request, $response);
if (!empty($result) && is_array($result)) {
$this->_authenticateProvider = $auth;
return $result;
}
}
Expand Down Expand Up @@ -783,4 +802,25 @@ public function flash($message, $type = 'error') {
$this->session->flash($message, 'error', $params + compact('key'));
}

/**
* If login was called during this request and the suer was successfully
* authenticated, this function will return the instance of the authentication
* object that was used for logging the user in.
*
* @return \Cake\Auth\BaseAuthenticate|null
*/
public function loginProvider() {
return $this->_authenticateProvider;
}

/**
* If there was any authorization processing for the current request, this function
* will return the instance of the Authorization object that granted access to the
* user to the current address.
*
* @return \Cake\Auth\BaseAuthorize|null
*/
public function authorizationProvider() {
return $this->_authenticateProvider;
}
}

0 comments on commit bbf7575

Please sign in to comment.