zefy / laravel-sso

MIT License
100 stars 75 forks source link

Route 301 redirect loop #19

Open dniccum opened 5 years ago

dniccum commented 5 years ago

At times, my broker won't load any page within the application because of a 301 redirect loop. I have noticed that sometimes I can fix the issue by visiting the "/" route first and then visiting the "/login" route, but this can even prove unsuccessful.

This is what my laravel-sso.php config file looks like on the broker:

<?php

return [

    'type' => 'broker',
    'serverUrl' => env('SSO_SERVER_URL', null),
    'brokerName' => env('SSO_BROKER_NAME', null),
    'brokerSecret' => env('SSO_BROKER_SECRET', null),

];

This is what my LoginController looks like:

private $broker;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/dashboard';

    /**
     * Create a new controller instance.
     *
     * @param LaravelSSOBroker $broker
     * @return void
     */
    public function __construct(LaravelSSOBroker $broker)
    {
        $this->middleware('guest')->except('logout');
        $this->broker = new $broker;
    }

    protected function attemptLogin(Request $request)
    {
        $broker = new LaravelSSOBroker;

        $credentials = $this->credentials($request);
        return $broker->login($credentials[$this->username()], $credentials['password']);
    }

    public function logout(Request $request)
    {
        $broker = new LaravelSSOBroker;

        $broker->logout();

        $this->guard()->logout();

        $request->session()->invalidate();

        return redirect('/');
    }

I have also added the necessary environment variables to the .env file.

dniccum commented 5 years ago

When I can get the page to load, I cannot login. After stepping through the code within the debugger, the error that I am seeing is "Invalid session id."