diff --git a/src/Subfission/Cas/Middleware/CASAuth.php b/src/Subfission/Cas/Middleware/CASAuth.php index 012224a..64bbc8a 100644 --- a/src/Subfission/Cas/Middleware/CASAuth.php +++ b/src/Subfission/Cas/Middleware/CASAuth.php @@ -31,11 +31,8 @@ public function handle($request, Closure $next) { return response('Unauthorized.', 401); } - else - { - $cas = app('cas'); - $cas->authenticate(); - } + $cas = app('cas'); + $cas->authenticate(); } return $next($request); diff --git a/src/Subfission/Cas/Sso.php b/src/Subfission/Cas/Sso.php index ca64ae1..0403329 100644 --- a/src/Subfission/Cas/Sso.php +++ b/src/Subfission/Cas/Sso.php @@ -9,7 +9,8 @@ * * @package Cas */ -class Sso { +class Sso +{ /** * Cas Config @@ -52,13 +53,14 @@ public function __construct($config, AuthManager $auth) public function authenticate() { // attempt to authenticate with CAS server - if ( phpCAS::forceAuthentication() ) - { + if (phpCAS::forceAuthentication()) { // retrieve authenticated credentials $this->setRemoteUser(); return true; - } else return false; + } else { + return false; + } } /** @@ -95,10 +97,8 @@ public function user() public function logout() { - if ( phpCAS::isSessionAuthenticated() ) - { - if ( $this->auth->check() ) - { + if (phpCAS::isSessionAuthenticated()) { + if ($this->auth->check()) { $this->auth->logout(); } Session::flush(); @@ -116,7 +116,7 @@ public function logout() */ private function cas_init() { - session_name( (isset($this->config['session_name']) ? $this->config['session_name'] : 'CASAuth' )); + session_name((isset($this->config[ 'session_name' ]) ? $this->config[ 'session_name' ] : 'CASAuth')); // initialize CAS client $this->configureCasClient(); $this->configureSslValidation(); @@ -124,8 +124,7 @@ private function cas_init() // set service URL for authorization with CAS server //\phpCAS::setFixedServiceURL(); - if ( ! empty($this->config[ 'cas_service' ]) ) - { + if ( ! empty($this->config[ 'cas_service' ])) { phpCAS::allowProxyChain(new \CAS_ProxyChain_Any); } // set login and logout URLs of the CAS server @@ -140,21 +139,21 @@ private function cas_init() */ private function configureCasClient() { - phpCAS::client(CAS_VERSION_2_0, $this->config[ 'cas_hostname' ], $this->config[ 'cas_port' ], $this->config[ 'cas_uri' ], false); + phpCAS::client(CAS_VERSION_2_0, $this->config[ 'cas_hostname' ], $this->config[ 'cas_port' ], + $this->config[ 'cas_uri' ], false); } private function configureSslValidation() { // set SSL validation for the CAS server - if ( $this->config[ 'cas_validation' ] == 'self' ) - { + if ($this->config[ 'cas_validation' ] == 'self') { phpCAS::setCasServerCert($this->config[ 'cas_cert' ]); - } else if ( $this->config[ 'cas_validation' ] == 'ca' ) - { - phpCAS::setCasServerCACert($this->config[ 'cas_cert' ]); - } else - { - phpCAS::setNoCasServerValidation(); + } else { + if ($this->config[ 'cas_validation' ] == 'ca') { + phpCAS::setCasServerCACert($this->config[ 'cas_cert' ]); + } else { + phpCAS::setNoCasServerValidation(); + } } } @@ -169,6 +168,19 @@ private function setRemoteUser() private function detect_authentication() { - if ( ($this->isAuthenticated = phpCAS::isAuthenticated()) ) $this->setRemoteUser(); + if (($this->isAuthenticated = phpCAS::isAuthenticated())) { + $this->setRemoteUser(); + } + } + + /** + * Get the attributes for for the currently connected user. This method + * can only be called after authenticate() or an error wil be thrown. + * @return mixed + */ + public function getAttributes() + { + // We don't error check because phpCAS has it's own error handling + return phpCAS::getAttributes(); } } \ No newline at end of file