Lernito OpenedX is a Django application that provides webhook integration between Open edX and Lernito services. It enables seamless communication and data synchronization between your Open edX instance and Lernito platform.
Please see the Open edX documentation for guidance on Python development in this repo.
To install this component in your Open edX instance:
Add the package to the requirements:
tutor config save --append OPENEDX_EXTRA_PIP_REQUIREMENTS=git+https://github.com/edSPIRIT/lernito-openedx.git
Save the secret in Tutor config:
tutor config save -s LERNITO_WEBHOOK_SECRET=YOUR_SECRET
You need to configure
LERNITO_WEBHOOK_SECRET
in your Django settings. This can be done in two ways:For Tutor-managed installations: Create a Tutor plugin that adds the required setting:
from tutor import hooks hooks.Filters.ENV_PATCHES.add_item( ( "openedx-common-settings", "LERNITO_WEBHOOK_SECRET = '{{ LERNITO_WEBHOOK_SECRET }}'", ) )
For non-Tutor installations: Add the setting directly to your Django settings file.
build the image and run the container:
tutor images build openedx # or openedx-dev for local development tutor dev|local|k8s start
The webhook endpoint accepts POST requests for enrolling users in courses. It handles both existing and new users.
POST /api/lernito/webhook/
X-Lernito-Signature
: HMAC SHA256 signature of the request payloadContent-Type: application/json
{
"email": "[email protected]",
"name": "First",
"family": "Last",
"username": "username",
"courseIds": ["course-v1:edX+DemoX+Demo_Course"]
}
For existing users:
{
"success": true,
"message": "User enrollment status verified for 2 course(s)"
}
For new users:
{
"success": true,
"message": "Enrollment allowance verified for 2 course(s)"
}
Invalid signature:
{
"success": false,
"message": "Invalid signature"
}
Invalid course:
{
"success": false,
"message": "Course course-v1:edX+DemoX+Demo_Course does not exist"
}
Invalid course format:
{
"success": false,
"message": "Invalid course key format: invalid-course-id"
}
Missing required fields:
{
"success": false,
"message": {
"email": ["This field is required"],
"courseIds": ["This field is required"]
}
}
{
"success": false,
"message": "Internal server error"
}
The API is idempotent, meaning:
- For existing users: It will enroll them in courses if not already enrolled
- For new users: It will create enrollment permissions that activate upon registration
- Multiple identical requests will produce the same result without creating duplicates
- Each request verifies and ensures the enrollment status is correct
You can test the webhook using the following Python script to generate a valid signature:
import hmac
import hashlib
import json
# Your webhook data
data = {
"email": "[email protected]",
"name": "Test",
"family": "User",
"username": "testuser",
"courseIds": ["course-v1:edX+DemoX+Demo_Course"]
}
# Convert to sorted JSON string
data_string = json.dumps(data, sort_keys=True)
# Generate signature
webhook_secret = "your_webhook_secret"
signature = hmac.new(
webhook_secret.encode('utf-8'),
data_string.encode('utf-8'),
hashlib.sha256
).hexdigest()
print(f"X-Lernito-Signature: {signature}")
PLACEHOLDER: Start by going through the documentation. If you need more help see below.
(TODO: Set up documentation)
If you're having trouble, we have discussion forums at https://discuss.openedx.org where you can connect with others in the community.
Our real-time conversations are on Slack. You can request a Slack invitation, then join our community Slack workspace.
For anything non-trivial, the best path is to open an issue in this repository with as many details about the issue you are facing as you can provide.
https://github.com/edSPIRIT/lernito-openedx/issues
For more information about these options, see the Getting Help page.
The code in this repository is licensed under the AGPL 3.0 unless otherwise noted.
Please see LICENSE.txt for details.
Contributions are very welcome. Please read How To Contribute for details.
This project is currently accepting all types of contributions, bug fixes, security fixes, maintenance work, or new features. However, please make sure to discuss your new feature idea with the maintainers before beginning development to maximize the chances of your change being accepted. You can start a conversation by creating a new issue on this repo summarizing your idea.
All community members are expected to follow the Open edX Code of Conduct.
The assigned maintainers for this component and other project details may be
found in Backstage. Backstage pulls this data from the catalog-info.yaml
file in this repo.
Please do not report security issues in public. Please email [email protected].