diff --git a/src/Subfission/Cas/Middleware/CASAuth.php b/src/Subfission/Cas/Middleware/CASAuth.php index 1f3847b..a5c0a96 100644 --- a/src/Subfission/Cas/Middleware/CASAuth.php +++ b/src/Subfission/Cas/Middleware/CASAuth.php @@ -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); + } } \ No newline at end of file