auto login to moodle from http url
Number of replies: 31How do I make a click on this hyperlink on my external website to be automatically pass the user & password so they are logged in to moodle?
Is it a simple url or is there extra tweaking to be done as well?
I prefer for users to be able to have no access to profiles etc., just take the classes & quizzes anonymously...
for this example:
http://www.mywebsite.com/moodle/
user: testy
password: 1234
Any direction would be appreciated!
Bill
Re: auto login to moodle from http url
Otherwise, one approach you could use would be to craft an HTML page that hard-codes the userID and password into a form. I think you'll need to use a form instead of a hyperlink because I suspect (but have not checked!) that Moodle expects to examine the POST information for login credentials, not the GET information.
Something along these lines:
<form action="index.php" method="post" name="login">
<input type="hidden" name="username" value="username_to_log_in_as" />
<input type="hidden" name="password" value="password_to_use" />
<input type="submit" value="Login" />
</form>
...the above is just a sketch but could get you going in the right direction.
Re: auto login to moodle from http url
How do I do that?
Regards,
Bill
Re: auto login to moodle from http url
I have an account and password setup for a certain course and would like to be able to go straight in.
I've tried the following:
http://www.abcdefg.com/course/view.php?id=3&username=student&password=password
I'm sure this must be possible - any ideas anyone??
thanks,
Lloyd
Re: auto login to moodle from http url
It used to be possible to pass usernames and passwords in URL's in the form http://username:password@url.com, but that was withdrawn by Microsoft a few years ago on security grounds (by security update 832894, according to http://support.microsoft.com/default.aspx?scid=kb;en-us;834489).
As far as I'm aware it's not possible to pass your username and password to Moodle in the URL in the way you've described. I'm sure the developers could do it if they wanted, as it should be an easy job to parse the query string from within PHP and extract the details, but it would open an enormous hole in Moodle's security, not least because your password would be visible in plain text for anyone who wanted to see it.
I think Bruce's suggestion would be your best bet, as the UN and PW would be passed invisibly. That will only get you to the front page of your Moodle though, I'm not aware of any way of getting you straight to a specific course.
Incidentally, for anyone running multiple Moodle installations, I have a script which will log you in to any one of them simply by selecting from a dropdown list box - I can post the code here if anyone wants it.
Chris
Re: auto login to moodle from http url
I am looking for some code or idea which will help users for my website abc.com to login directly to moodle under abc.com/moodle after loged in to abc.com
Any help please?
Re: auto login to moodle from http url
Hi everyone.
I think we are dealing with 2 separate issues here:
- Automatic authentication (single sign-on)
- Direct access to a specific course
I have been working on both over the past few weeks and here is what I have achieved.
Automatic authentication (single sign-on)
We use LDAP authentication, with Moodle checking our main directory server to check credentials. Our portal uses the same directory server (Novell e-Directory). Once a user has authenticated to our portal, we didn’t want them to have to authenticate to Moodle as well.
On login to our portal, username and password are stored as session variables to be used later to pass to Moodle.
Our Moodle hyperlink goes to a redirection page which contains a html form populated with values from the session variables. This form is auto-submitted to the Moodle login page and automatically logs the user in. The ASP and JavaScript code for this page is below:
**************************************************************
<html>
<head>
<SCRIPT LANAGUAGE=JAVASCRIPT>
function autoSubmit(){
document.form.submit();
}
</SCRIPT>
</head>
<body>
<%
dim append
if request.querystring("id") <>"" then
append = "?id=" & request.querystring("id")
else
append = ""
end if
%>
<%if session("LoggedIn") <> true Then
response.redirect "https://moodle.college.ac.uk/login/index.php"
Else
%>
<form action="https://moodle.college.ac.uk/login/index.php<%=append%>" method="post" name="form" id="form">
<p><input type="hidden" name="username" size="15" value = "<%=session("UserName")%>"/></p>
<p><input type="hidden" name="password" size="15" value = "<%=session("UserPass")%>"/></p>
<p><input type="hidden" name="Submit" value="" /></p>
</form>
<SCRIPT LANAGUAGE=JAVASCRIPT>
autoSubmit()
</SCRIPT>
<%End if%>
</body>
</html>
**************************************************************
If you want to use a single username and password for all, hard code it into the form values.
Direct access to a specific course
The 2nd point regards auto redirection to a course once logged in.
Each course has an ID in Moodle. I pass the required course ID in the query string, and have added a few lines to moodle\login\index.php to pick up the ID if it is present. Once authenticated, Moodle redirects itself to the requested course.
**************************************************************
Added to moodle\login\index.php
//Added by Robin 23 May 2007
if($_GET['id'] <> "")
{
$SESSION->wantsurl = $CFG->wwwroot.'/course/view.php?id='.$_GET['id'];
}
**************************************************************
My next problem to resolve concerns an error I am getting which regards cookies.
If anyone has any comments or improvements, I would appreciate them – pretty new to this stuff.
Hope this helps.
Thanks,
Robin
Re: auto login to moodle from http url
The following if() checks with isset to see if the URL string exists.
I have also changed the id to courseid so that I can use the second if() to direct users directly to a particular forum with ?forumid=12345
if( isset($_GET['courseid']) && $_GET['courseid'] <> ""){
$SESSION->wantsurl = $CFG->wwwroot.'/course/view.php?id='.$_GET['courseid'];
}
// for direct to a forum
if( isset($_GET['forumid']) && $_GET['forumid'] <> ""){
$SESSION->wantsurl = $CFG->wwwroot.'/mod/forum/view.php?id='.$_GET['forumid'];
}
I am using this change along with the toro-gateway_portlet in uPortal to allow access to a forum with a single click.
I placed the above code just after
require_once("../config.php");
I'm not sure that is the best or correct place but it is working.
I also noted the following line further down the login.php page.
$loginurl = (!empty($CFG->alternateloginurl)) ? $CFG->alternateloginurl : '';
Should this sort of change be made in a renamed copy of login.php and set the alternateloginurl to that new page.
Re: auto login to moodle from http url
Did you check security issues in your single sign-on approach?
Be careful because that way the password is going to be openly written in client page source!
Does anyone have further considerations about this?
cheers,
susana
Re: auto login to moodle from http url
Re: auto login to moodle from http url
- http://localhost/customLogin.php?username=1234&course_id=222 , here we need to read parameter username from the URL and autologin to the course. this user can be created already in the database or we can create on fly(registering) and password will be same for all th users.
- I would liek to know the exacr code changes to read the user from the querystring and autologin by showing course page directly.
I need this urgently.
Tina.
Re: auto login to moodle from http url
Re: auto login to moodle from http url
Thank you for the quick response, does that allow me to enroll the user automatically without login page and directly to course page with user in the database.
One more question, I would like to add 20,000 users into the database, Is there any automate process to do that.Please let me know as soon as possible.
Thanks
tina
Re: auto login to moodle from http url
In our organization we are working with two moodle instance one is our own corporate LMS and the other one is of Vendor moodle site as they refused to provide us off-the-shelf courses they are providing online access in order to have track number of licenses. In this context we have already configured LDAP authentication and secured the SSO accross the organisation, now once the user log into the corporate moodle again he has to click on a link to take the online course which is a kind of redirection url which redirect the users and does the automatic logins.
But I am looking a way that intead of clicking on the link to access another moodle and getting logged in can we have a trick to pass the login credentials automatically without accessing the page in the background and whenever user wants they select the courses link and navigate the other moodle site.
I am not sure if I have put my question appropriately, Please do correct my if any.
Looking for the help in this aspect.
Thanks !!!
Re: auto login to moodle from http url
(Of course, if you are not using Moodle for any analytics then perhaps this is irrelevant in your case.)
One thing, though: you probably don't want to pass the username and password in clear text, so it might be necessary to encrypt them before creatnig the links into Moodle and then decrypt them inside /login/index.php. This would require editing the code of that file.
Good luck!
Re: auto login to moodle from http url
Have a look at http://docs.moodle.org/en/admin/uploaduser, if you haven't already.
The columns we use are the following, and the password is always "changeme", as to force them to change their password on first login.
username | password | firstname | lastname | department | idnumber | course1 | role1 |
Mohd, have you thought about http://docs.moodle.org/en/Moodle_Network ?
Re: auto login to moodle from http url
"This authentication plugin lets you pass serialized user data to the Moodle login page to create and enroll users on-the-fly.
If they have already been authenticated then it only verifies and logs them in.
If something goes wrong it will redirect to an external error page.
It was created and designed to offer transparent logins from external sources."
I've attached the zip of the code. Hope it helps!
Re: auto login to moodle from http url
Some javascript 'setTimeout' are necessary to give time for the login page to koad.The frames solution is more adaoted to be able to select which of your different courses you want to connect to.
Re: auto login to moodle from http url
Hi Allen
I have installed this plugin but it doesnt automatically log the user in. Once you have logged in to moodle then it seems to log you in automatically via the link. I am doing something wrong? I have followed the instructions to install.
Thanks
Pete
Re: auto login to moodle from http url
i noticed it only works with manual or db accounts. How or where would you change it to work with an LDAP (eDirectory) for authentication instead?
thanks
Chris
Re: auto login to moodle from http url
What we would really like to do now is have the user be directly taken to the first enrolled course page. We tried a simple redirect(), setting $SESSION->wantsurl and implementing user_authenticated_hook() but without joy so far.
I don't really know enough abotu Moodle yet to know how to make this happen so any hints would be very welcome!
Simon
Re: auto login to moodle from http url
Hi Rhodry,
Any chance you can post me this code with a drop down menu to log into moodle?
Thanks Pete
Re: auto login to moodle from http url
I am trying to create a single sign on via a hyperlink using the ASP/Javascript form that you sent but am getting the following errors when I click on a link to the form:
"/>
"/>
Can you please help as I am new to all this?
Thanks
Pete
Re: auto login to moodle from http url
Here's some code I picked up from the forums that works on my Moodle installation:
<?php
$username = stripslashes($_GET['username']);
$password = stripslashes($_GET['password']);
?>
<form action="http://mymoodle/login/index.php" method="post" name="login" id="form">
<p><input type="text" name="username" value="<?php echo $username ?>">
<p><input type="hidden" name="password" value="<?php echo $password ?>">
<script language="JavaScript">
function Validate()
{
document.login.submit();
}
Validate();
</script>
</form>';
?>
Re: Login Bookmarklet was auto login to moodle from http url
The main advantage of a single link is so as to be able to promote Moodle.
But it would also be nice to save the Admin's time. I wonder if would be possible to put this sort of thing into a bookmarklet! One click and I am logged in. Only I use my computer.
Re: auto login to moodle from http url
Sorry, some further instructions:
1) Save the code in a file of your choice and location, eg. http://mymoodle/mylocation/myfile.php
2) Call the file in an URL with the username and password you've created as follows (replace myuser and mypass with own username and password):
https://mymoodle/mylocation/myfile.php?username=myuser&password=mypass
Hope this helps.
Re: auto login to moodle from http url
I have multiple moodle installs and would like to easily switch between them.
Re: auto login to moodle from http url
what version of moodle are you using ??
have a look at moodle "network authentication" plugin which meets your objective
Re: auto login to moodle from http url
Re: auto login to moodle from http url
Folks,
I have couple of URLS on my clients site on clicking that it should Auto login the user to moodle for first time and and redirect directly to course /page of a course in new tab .
and when he clicks on second url it should simply open course of Moodle in other tab
can any one please help me !
Thanks in advance
Re: auto login to moodle from http url
I've just had a requirement for an auto-login or login via URL and after spending five minutes sifting through various ideas decided to get on and do it myself.
A simple modification to /login/index.php seems to do the trick, round about line 46 (somewhere after "$frm = false;":
$frm = false;
$user = false;
$U=@$_GET['U'];
$P=@$_GET['P'];
if ((strlen($U)>=1) && (strlen($P)>=1)){
$frm->username = $U;
$frm->password = $P;
}
$authsequence = get_enabled_auth_plugins(true); // auths, in sequence
foreach($authsequence as $authname) {
$authplugin = get_auth_plugin($authname);
$authplugin->loginpage_hook();
}
The new code shown in red. This works with the URL http://127.0.0.1/login/index.php?U=username&P=password.
Re: auto login to moodle from http url
Just had a similar request from our Teachers. (Auto login unregistered users into a Questionnaire)
Here is a YUI "AJAX" code I used inside a Label resource on the front page of the Course:
(replace the bold parts with your own values)
<p><button id="startme">Let me answer the questionnaire</button></p>
<script type="text/javascript">// <![CDATA[
Y.one('#startme').on('click',function(){
Y.io('http://YOUR-MOODLE/login/index.php',{
method:'POST',
data: {
username: 'guestuser',
password: 'guestpassword',
},
on:{
complete:function(id,response){
Y.one('#startme').setHTML('Connected');
Y.config.win.location = 'http://YOUR-MOODLE/mod/questionnaire/view.php?id=XXX';
},
start:function(id,response){
Y.one('#startme').setHTML('Logging in...');
}
}
});
});
// ]]></script>