Skip to content

Commit

Permalink
Merge pull request #10 from subfission/develop
Browse files Browse the repository at this point in the history
Feature request getAttributes() #9
  • Loading branch information
subfission committed Aug 20, 2015
2 parents 271c5d3 + 529227b commit 25519bc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
7 changes: 2 additions & 5 deletions src/Subfission/Cas/Middleware/CASAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
54 changes: 33 additions & 21 deletions src/Subfission/Cas/Sso.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
*
* @package Cas
*/
class Sso {
class Sso
{

/**
* Cas Config
Expand Down Expand Up @@ -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;
}
}

/**
Expand Down Expand Up @@ -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();
Expand All @@ -116,16 +116,15 @@ 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();
$this->detect_authentication();

// 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
Expand All @@ -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();
}
}
}

Expand All @@ -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();
}
}

0 comments on commit 25519bc

Please sign in to comment.