Reputation: 1147
I have installed a Moodle instance on a server and a Drupal instance on the same server. But, they both use different domains.
drupal.example.com (running Drupal 7.44) (hosted on Server A)
www.example.net/moodle (running Moodle 2.6.2) (hosted on same server as above)
Requirement: I want to use Moodle functions in Drupal. I want to let my Moodle users login to Drupal using their Moodle credentials.
The user, who has logged into Drupal using their Moodle credentials, should have access to their Moodle courses on Drupal.
My approach: Include Moodle configuration file in a external PHP file (hosted on Drupal site), send AJAX requests to the PHP file to authenticate users, get list of courses and other information from Moodle to Drupal.
I'm still working on the requirement. Wondering if there is any simple approach to meet this requirement.
Upvotes: -1
Views: 865
Reputation: 11
first you need enable and using moodle webservices ,follow this link.
then for implement simple SSO you can use moodle-auth_userkey plugin, this link. will help you.
Upvotes: 0
Reputation: 2091
You are on the right track, I have also implemented not same but similar solution so that user can auto login to moodle if they login to another system. I am sharing my code if it can help you:-
<?php
require('config.php');
$name=strtoupper($_REQUEST['username']);
$password=$_REQUEST['password'];
$dashboard = $CFG->wwwroot;
$user = authenticate_user_login($name, $password);
if(complete_user_login($user))
{
$actual_link = "http://$_SERVER[HTTP_HOST]/moodlevxl/login/logout.php?sesskey=".$user->sesskey;
header("http://$_SERVER[HTTP_HOST]");
?>
<script>
location.href = "Your callback url";
</script>
<?php
//print_r($_COOKIES);
//echo "login";
}
else
{
echo "not login"; die;
}
?>
Upvotes: 0
Reputation: 428
There is no simple solution to this requirement. Still, you can achieve this.
For SSO and other web services refer this link.
Upvotes: -1
Reputation: 2340
Moodle has a very extensive set of webservices for exactly this use case and there are a few ways of achieving SSO between the two systems if you take a look around.
Upvotes: 2