Skip to content

Commit

Permalink
Merge pull request #17 from subfission/master
Browse files Browse the repository at this point in the history
Merging with master branch
  • Loading branch information
subfission committed Jan 21, 2016
2 parents e83030b + 179ec43 commit 1e5a031
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions src/Subfission/Cas/Middleware/CASAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,39 @@
use Closure;
use Illuminate\Contracts\Auth\Guard;

class CASAuth {
class CASAuth
{

protected $auth;
protected $cas;
protected $auth;
protected $cas;

public function __construct(Guard $auth)
{
public function __construct(Guard $auth)
{
$this->auth = $auth;
$this->cas = app('cas');
}
$this->cas = app('cas');
}

/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($this->auth->guest() || ! $this->cas->isAuthenticated())
{
if ($request->ajax())
{
return response('Unauthorized.', 401);
}
// We setup CAS here to reduce the amount of objects we need to build at runtime. This
// way, we only create the CAS calls only if the user has not yet authenticated.
$this->cas->authenticate();
session()->put('cas_user', $this->cas->User());
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($this->auth->guest() || ! session()->has('cas_user')) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
}
if ( ! $this->cas->isAuthenticated()) {
$this->cas->authenticate();
}
// We setup CAS here to reduce the amount of objects we need to build at runtime. This
// way, we only create the CAS calls only if the user has not yet authenticated.
session()->put('cas_user', $this->cas->User());
}

return $next($request);
}
return $next($request);
}
}

0 comments on commit 1e5a031

Please sign in to comment.