24Slides / laravel-saml2

[Laravel 5.4+] An integration to add SSO to your service via SAML2 protocol based on OneLogin toolkit with support of multiple Identity Providers
MIT License
227 stars 67 forks source link

Question: Redirect to intended URL after successful login #79

Open olivergernetzke-pon opened 9 months ago

olivergernetzke-pon commented 9 months ago

Hi there!

With standard Laravel authentication and login, I can redirect the user back to the page he originally wanted to go to (with redirect()->intended(...)). So for example:

How can we do that with this SAML2 package? Can we somehow put this into the relay_state_url?

Many thanks in advance for your help. I hope my question is clear. :)

RaphMartinHEC commented 6 months ago

Hello ! I have the same problem. I can only redirect to a specific page (with the relay_state_url or 'loginRoute' => env('SAML2_LOGIN_URL')) But with nothing put in one of these two, it loops over the {UUID}/login link

Thanks !

RaphMartinHEC commented 5 months ago

Hello again,

I solved the problem by modifying the Auth middleware like this:

protected function redirectTo(Request $request): ?string
{
    $UUID = 'my-UUID';
    $intendedUrl = $request->url();

    $fullUrl = "https://my.site/saml2/$UUID/login?returnTo=$intendedUrl";

    return url($fullUrl);
}

It can be done in less lines though

jithintc commented 2 months ago

This is the issue with the redirectUrl or the relaystate url is empty. You may have to use to saml_url('intented url') or saml_route('intented route') when providing the saml login url. If you have a default url, add it to to the sam2 config file as loginRoute to avoid redirect loop