Submit a ticket My Tickets
Welcome
Login  Sign up
Open navigation

How to Set Up the Basic Integration with Auth0

Auth0 is a flexible, cloud-based identity platform for developers, allowing them to easily add authentication and authorization services to their applications, eliminating friction and the complexity of APIs and custom development.


How to enable Single Sign-On (SSO) for your LearnWorlds school using Auth0.

Request access to LearnWorlds Restful API

Go to My accountPremium Members, and Request API keys (available in Learning Center plans and above).


This will trigger a request to our support team and within 1-2 working days your API access will be enabled. You will receive an email from us informing you of the enabling of the service along with usage examples and credentials including your API endpoint, LearnWorlds Client ID, and Client Access Token. Store those two somewhere as you will need them for setting up your Auth0 application.

Create an Auth0 application

Access your Auth0 tenant management panel. Visit the applications tab and click on Create Application.

In the Create Application modal that will appear enter your application name and select Regular Web Application as the application type and click on Create.

Access the Application Settings from the tab.

Set the following variables to your settings:


Application Login URI:

https://www.YOURSCHOOL.com/?msg=not-logged-in 

Allowed Callback URLs:

https://www.YOURSCHOOL.com, https://www.YOURSCHOOL.com/start

Allowed Logout URLs:

https://www.YOURSCHOOL.com, https://www.YOURSCHOOL.com/start

Allowed Web Origins:

https://www.YOURSCHOOL.com, https://SCHOOLAPI.com

Allowed Origins (CORS):

https://www.YOURSCHOOL.com, https://SCHOOLAPI.com


Note: Use the school API URL as provided by the LearnWorlds Support team in the email of the first step.

Customize your application

Setup your applications' customization options and addons based on your needs. You can follow Auth0's documentation to fully customize every aspect of your users' authorization experience.


Setting up different connections:

https://auth0.com/docs/connections

Branding and Customization:

https://auth0.com/docs/brand-and-customize

Create a new Rule

Visit the Rules page from the sidebar.

Set settings variables:


Key: lwClientId

Value: The LearnWorlds Client id you received from us

Key: lwApi

Value: The LearnWorlds API endpoint you received from us

KeylwClientToken

Value: The LearnWorlds Client Token you received from us

Key: lwSchoolUri

Value: Your School's domain name ex. https://www.myschool.com


Click on Create Rule to create a new Rule and then select the Empty Rule option.

    

Copy and paste the following code snippet and click on Save Changes.

function (user, context, callback) {
  const axios = require('axios@0.19.2');
  user.user_metadata = user.user_metadata || {};
  
  const learnWorldsId = user.user_metadata.lwUserId;
  
  const ssoData = {
    username: user.nickname,
    avatar: user.avatar,
    email: user.email,
    redirectUrl: `${configuration.lwSchoolUri}/start`
  };
 
  if (learnWorldsId) {
    ssoData.user_id = learnWorldsId;
  }

  const options = { method: 'POST',     url: `${configuration.lwApi}/sso`,     headers: {        'content-type': 'application/json',       'Lw-Client': configuration.lwClientId,       'Authorization': `Bearer ${configuration.lwClientToken}`     },     data: JSON.stringify(ssoData) };
  axios(options)     .then( (res) => {       if (res.data.success) {         user.user_metadata.lwUserId = res.data.user_id;         auth0.users.updateUserMetadata(user.user_id, user.user_metadata)         .then(function(){           context.redirect = {             url: res.data.url           };           return callback(null, user, context);         })         .catch(function(err){           callback(err);         });       }       else {         console.error('Could not authorize you to learnworlds.');       }     })     .catch( err => {       console.error('Could not authorize you to learnworlds');     });   }

Note: Make sure that the Rule you just created is prioritized as the last one in case you have more rules for your authorization flow.

Get In touch with us

Contact our support team and provide them with your Auth0 application id, tenant id, and location as shown below. Then you'll be informed as soon as the integration gets enabled from us.


Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.