dwightwatson/autologin

Other Auth frameworks

Closed this issue · 4 comments

Can we override the controller? That way we can enable Sentry or any other Auth strategy having the user ID and the redirect URL.

Maybe even provide the 2 or 3 most popular bundled.

I wasn't really sure how to package this with different implementations, I think I need to adjust the structure a little more to allow people to swap out the user provider as well as the authentication provider. I'll have a think about this.

In the meantime, here is an autologin controller I've been using which supports Sentry. Let me know how you go with this!

class AutologinController extends BaseController 
{
    /**
     * Process the autologin token and perform the redirect.
     */
    public function autologin($token)
    {
        if ($autologin = Autologin::validate($token))
        {
            // Active token found, login the user and redirect to the
            // intended path.
            try
            {
                $user = Sentry::findUserById($autologin->getUserId());

                Sentry::login($user);
            }
            catch (Cartalyst\Sentry\Users\LoginRequiredException $e)
            {
                return Redirect::route('login');
            }
            catch (Cartalyst\Sentry\Users\UserNotFoundException $e)
            {
                return Redirect::route('login');
            }
            catch (Cartalyst\Sentry\Users\UserNotActivatedException $e)
            {
                return Redirect::route('login');
            }

            return Redirect::to($autologin->getPath());
        }

        // Token was invalid, redirect back to the home page.
        return Redirect::route('login');
    }
}

Sorry, to be a little clearer on this - yes you can override the controller. If you publish the package config using php artisan config:publish watson/autologin you are able to adjust package options including which controller is used.

Been a bit busy, so apologies for the delay. Just tagged a new version (0.2.0) which introduces AuthenticationInterface with support for Laravel Auth and Sentry out of the box. I was going to implement other libraries but I wasn't sure what else was popular.