2

I'm setting up a single-sign-on feature for moodle from a laravel website.

  1. User accesses the laravel site

  2. User logs in

  3. User clicks a link to Moodle

  4. The user is automatically logged into Moodle without having to reenter their username and password.

If the user bookmarks or directly accesses Moodle, they can still login directly there with their username and password.

I have tried to user php cURL to post username and password to the login url.

$url =  "http://moodle.site.com.na/sso/login/index.php";
$postData = array('username' => $username, 'password' => $password);
try {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    curl_close($ch);
}
catch(Exception $e){
    dd($e);
}
return $response;​

When the single-sign-on is successful, then the user should be automatically logged into moodle site without having to re-enter their username and password.

executable
  • 3,365
  • 6
  • 24
  • 52

1 Answers1

0

Yes - there are a couple common solutions depending on your needs:

Hope it goes well!

John
  • 544
  • 3
  • 7
  • I need help on how to do it, below is my scenario... User accesses the main siteA User logs in siteA User clicks a link to Moodle(SiteB) The user is automatically logged into Moodle(SiteB) without having to reenter their info If the user bookmarks or directly accesses Moodle(SiteB), they can still login directly there – Ndeya Taapopi Mar 28 '19 at 19:15