Error with Laravel and phpCAS cannot redirect on failed authentication.

292 Views Asked by At

I implemented phpCAS as a Service Provider in my app that is running Laravel 5.1. Every single page in my app needs to be authorized so I created a Helper function that authenticates with phpCAS on my main app.blade.php file. The Helper function authenticates and then retrieves user information from my database so I can get user properties (id, fullName, etc.)

Here is the helper function:

public static function full_authenticate() {
    Cas::authenticate();
    $username = Cas::getCurrentUser();
    $userinfo = Users::where('username', '=', $username)->first();
    return $userinfo;
    if (!is_null($userinfo)) {
        return "ERROR." //THIS DOES NOT WORK
    } else {
        return View::share('userinfo', $userinfo);
    }
}

This is how it's used in app.blade.php (as an example)

{{ Helpers::full_authenticate()->fullname }}

The authentication works perfectly and if you are in the Users model, it will load up your information no problem. The issue I am having is when you authenticate successfully in CAS, but are not in the Users table, I want to be able to throw a 403 error or redirect to another view or just say some sort of message, but no matter what I put in the "return" section, it doesn't work. I think it has something to do with my helper function running behind a controller, but I have no idea.

Also looked into integrating CAS into middleware, but not sure how to pursue that.

Any ideas would be awesome! Thanks in advance!

0

There are 0 best solutions below