SSO Bypassing Login Page

Re: SSO Bypassing Login Page

by Michael Milette -
Number of replies: 3
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Anna,

If you made your own theme, you can probably apply format_text or format_string on the alternatelogin URL field. But what you suggested could work too. Note that it is not just the sesskey that you need. You also need to pass the encoded URL parameter as this is where SSO



OAuth2 sends you after you successfully login.

I recently discovered a flaw in my approach which is preventing the login from working when I try to access a course directly using a link or bookmark before being logged in. I am going to need to rethink my approach over the next few days. I will try to remember to come back here to post an update when I figure it out. I really want to bypass the Moodle login screen and go directly to the Oauth2 login page.

Feel free to share your ideas if you have it working.

Best regards,

Michael
In reply to Michael Milette

Re: SSO Bypassing Login Page

by Benjamin Schröder -
Picture of Plugin developers

Hi Michael,

Thank you very much Michel! I tested your local plugin with my Moodle 3.8.3 instance and also activated Kerberos SSO + LDAP Authentication. Everything was fine with the installation and I can also call the URL with "local/login/ but then the site recognizes than I'm already authenticated with the SSO and my LDAP Account. So I'm not able to logout with my LDAP Account to login into my Admin Account.

Maybe if I delete the "check if login" code in the local plugin. What do you think? Any ideas?

Best regards,

Ben

In reply to Benjamin Schröder

Re: SSO Bypassing Login Page

by Michael Milette -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Benjamin,

The reason it is logging you out and right back in again is because you are only ogging out of Moodle but not your SSO provider. In order to properly log out, you need to be logged out of you SSO provider. You may also need to logout of Moodle too afterwards.

The trick to getting this to work is to find a way to end up logged out of both. There are two possibilities that I know of.

Some authentication systems provide Moodle with a logout URL automatically. I don't know for sure if yours does. It may be something that you can configure in the authentication plugin settings.

In my case, after studying the SSO provider's documentation, I discovered that it supported a redirection parameter. The URL is where the SSO provider sends the web browser after you are logged out of SSO. The result is that the user ends up logged out of both systems.

So I did some customization to change the logout URL toinclude the extra parameter. Now when the user logs out, they are now clicking a link that will log them out of the SSO system and then get redirected to the Moodle logout URL. Unfortunately Moodle lacks an alternate Custom logout URL option like the one for logging in.

So far this has been working great - for the most part. There remains one a small annoyance which I have not had time to work out yet.

After logging out, when I click on a link to the course I was in before I logged out, instead of taking me to the course description as one would expect, it takes me to the SSO login page. So what I think I need to do now is to create a custom logout.php that will also delete the session cookie so that Moodle stops trying to redirect me back to the last page I was on.

I will probably add an option for that but I am not sure that I will be able to programmatically override the default Moodle logout URL path. You may still need to do some custom work in the theme.

Hope you find this helpful.

Best regards,

Michael
In reply to Michael Milette

Re: SSO Bypassing Login Page

by Benjamin Schröder -
Picture of Plugin developers
Hi Michael,

Sorry for the delay responding to your comment. Thank you very much for the post. I found a solution for my case in MDL-40312. It's still a core hack of the ldap plugin. Now I can logout with my SSO-Account and login into my admin account. Not the perfect solution but stable.

Hope you find this helpful.

Best regards,

Ben