Back

[LMS] How to sign-in/register users from your website using HTTP Single Sign-On (SSO)

Enable your website users to register or log in once and effortlessly navigate across BrainCert's Enterprise LMS without needing to log in again. Single sign-on creates a better user experience and reduces the need to create the users manually in the LMS.

Single sign-on (SSO) is a session and user authentication service that permits a user to use one set of login credentials (e.g., username and password) to access multiple applications. The service authenticates the end user for all the applications the user has been given rights to and eliminates further prompts when the user switches applications during the same session.

What are the requirements?

  • The feature integrates easily with your own website with few lines of code, making it quick and straightforward to set up Single Sign-On (SSO) your entire website users. No need for complex identity provider setup or Security Assertion Markup Language 2.0 (SAML 2.0) integration.

How does it work?

  • Copy the attached SSO code and use the example PHP code in your website to register new users and allow SSO of existing users without typing their username and password in LMS login screen.
  • Identity mapping is based on the email address which must be the same in both origin (your website) and target (Enterprise LMS).

How do I use it in my website?

To enable HTTP SSO in your Enterprise LMS, click on "Extensions",


Enable HTTP SSO extension, and save your API and Auth keys. A new user account will be created in the LMS when your website users click on the SSO hyperlink for the very first time.

Copy the following PHP library and use it in your website where you would like the users to launch the LMS link. You can also set Group IDs separated by a comma to easily add users to LMS groups.

<?php 
$lmsurl ='YOUR_LMS_URL'; # Your LMS Domain url. For example, https://acme.braincert.com/.
$email = "This email address is being protected from spambots. You need JavaScript enabled to view it."; # Email address of the user
$username = "YOUR_USERNAME"; # Username 
$first_name = "YOUR_FIRSTNAME"; # First name of the user
$last_name = "YOUR_LASTNAME"; # Last name of the user
$group_id = "YOUR_LMS_GROUP_IDS"; # LMS group IDs separated by a comma
$data = array();
$data['sso_api_key'] = "YOUR_API_KEY"; # API KEY
$data['sso_auth_key']= "YOUR_AUTH_KEY"; # AUTH KEY
$data['username'] = $username;
$data['email'] = $email;
$data_string = json_encode($data); 
$lmsurl = trim($lmsurl,"/");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $lmsurl."/?task=request_token");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result_json = curl_exec($ch);
$result = json_decode($result_json, TRUE); 
if($result['status']=='ok'){
      $token =  $result['token'] ;
      echo $ssourl = "<a href='".$lmsurl."/?token=".$result['token']."&email=".$email."&username=".$username."&first_name=".$first_name."&last_name=".$last_name."&group_id=".$group_id."'>".$email."</a>" ;
}
else if($result['status']=='error'){
      echo $result['message'] ;
}
?>

Put the above code in a page and populate relevant parameters such as email address using DB queries specific to your website. The hyperlink may look like this when you mouse over:

<a href='https://mylmsdomain.braincert.com/?token=59eeaasasa42cad9&email=This email address is being protected from spambots. You need JavaScript enabled to view it.&username=JohnW&first_name=John&last_name=Wick&group_id=1,2,3'>


Where do I find Group ID?

You can find the ID of the group under "Account & Settings" --> "List groups".


How to email account details to new users?

Remember to enable account notification email, so the new account details including generated password will be emailed to the user after registration automatically.



Author
BrainCert
Date Created
2015-10-16 17:06:02
Date Updated
2017-10-23 23:13:18
Views
3185