Skip to content

Webhooks to integrate Open edX with Lernito services

License

Notifications You must be signed in to change notification settings

edSPIRIT/lernito-openedx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lernito-openedx

PyPI CI Codecov Documentation Supported Python versions License status-badge

Purpose

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.

Getting Started with Development

Please see the Open edX documentation for guidance on Python development in this repo.

Installation

To install this component in your Open edX instance:

  1. Add the package to the requirements:

    tutor config save --append OPENEDX_EXTRA_PIP_REQUIREMENTS=git+https://github.com/edSPIRIT/lernito-openedx.git
  2. Save the secret in Tutor config:

    tutor config save -s LERNITO_WEBHOOK_SECRET=YOUR_SECRET
  3. 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.

  4. build the image and run the container:

    tutor images build openedx  # or openedx-dev for local development
    tutor dev|local|k8s start

Webhook API Documentation

The webhook endpoint accepts POST requests for enrolling users in courses. It handles both existing and new users.

Endpoint

POST /api/lernito/webhook/

Request Headers

  • X-Lernito-Signature: HMAC SHA256 signature of the request payload
  • Content-Type: application/json

Request Body

{
    "email": "[email protected]",
    "name": "First",
    "family": "Last",
    "username": "username",
    "courseIds": ["course-v1:edX+DemoX+Demo_Course"]
}

Response Scenarios

1. Successful Enrollment (200 OK)

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)"
}

2. Authentication Errors (401 UNAUTHORIZED)

Invalid signature:

{
    "success": false,
    "message": "Invalid signature"
}

3. Validation Errors (400 BAD REQUEST)

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"]
    }
}

4. Server Errors (500 INTERNAL SERVER ERROR)

{
    "success": false,
    "message": "Internal server error"
}

Behavior

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

Testing

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}")

Getting Help

Documentation

PLACEHOLDER: Start by going through the documentation. If you need more help see below.

(TODO: Set up documentation)

More Help

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.

License

The code in this repository is licensed under the AGPL 3.0 unless otherwise noted.

Please see LICENSE.txt for details.

Contributing

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.

The Open edX Code of Conduct

All community members are expected to follow the Open edX Code of Conduct.

People

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.

Reporting Security Issues

Please do not report security issues in public. Please email [email protected].

About

Webhooks to integrate Open edX with Lernito services

Resources

License

Stars

Watchers

Forks

Packages

No packages published