Sai Kiran Sripada
Sai Kiran Sripada

Reputation: 1147

How to use Moodle API or Moodle functions in Drupal?

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

Answers (4)

Milad Karimiyan
Milad Karimiyan

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

DHRUV GUPTA
DHRUV GUPTA

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

Sudeep nayak
Sudeep nayak

Reputation: 428

There is no simple solution to this requirement. Still, you can achieve this.

  1. Customize Moodle UI as Drupal.
  2. Implement SSO with Moodle.
  3. Add a link to the course list on your Drupal dashboard.

For SSO and other web services refer this link.

Upvotes: -1

Andrew Hancox
Andrew Hancox

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

Related Questions