mint-o-badges / badgr-server

Open Badge issuing and management with Django
GNU Affero General Public License v3.0
2 stars 1 forks source link

Badgr Server

Digital badge management for issuers, earners, and consumers

Badgr-server is the Python/Django API backend for issuing Open Badges. In addition to a powerful Issuer API and browser-based user interface for issuing, Badgr offers integrated badge management and sharing for badge earners. Free accounts are hosted by Concentric Sky at Badgr.com, but for complete control over your own issuing environment, Badgr Server is available open source as a Python/Django application.

See also badgr-ui, the front end written in Angular that serves as users' interface for this project.

About the Badgr Project

Badgr was developed by Concentric Sky, starting in 2015 to serve as an open source reference implementation of the Open Badges Specification. It provides functionality to issue portable, verifiable Open Badges as well as to allow users to manage badges they have been awarded by any issuer that uses this open data standard. Since 2015, Badgr has grown to be used by hundreds of educational institutions and other people and organizations worldwide. See Project Homepage for more details about contributing to and integrating with Badgr.

Open Badges Implementation

Badgr-server hosts standard-compliant endpoints that implement the Open Badges 2.0 specification. For each of the core Open Badges objects Issuer, BadgeClass and Assertion, there is a standards-compliant public JSON endpoint handled by the Django application as well as an image redirect path.

Each JSON endpoint, such as /public/assertions/{entity_id}, performs content negotiation. It will return a standardized JSON-LD payload when the path is requested with no Accept header or when JSON payloads are requested. Additionally, User-Agent detection allows bots attempting to render a preview card for social sharing to access a clean HTML response that includes Open Graph meta tags. Other clients requesting text/html will receive a redirect to the corresponding public route on the UI application that runs in parallel to Badgr-server where humans can be presented with a representation of the badge data in their browser.

Each image endpoint typically redirects to an image within the associated storage system. The system can convert from SVG to PNG and adapt images to a common "wide" radio for the images needed for card-based previews in many social network systems.

How to get started on your local development environment.

Prerequisites:

Copy local settings example file

Copy the example development settings:

NOTE: you may wish to copy and edit the production config. See Running the Django Server in "Production" below for more details.

Customize local settings to your environment

Edit the settings_local.dev.py and/or settings_local.prod.py to adjust the following settings:

Additional configuration options

Set or adjust these values in your settings_local.dev.py and/or settings_local.prod.py file to further configure the application to your specific needs.

Running the Django Server in Development

For development, it is usually best to run the project with the builtin django development server. The development server will reload itself in the docker container whenever changes are made to the code in apps/.

To run the project with docker in a development mode:

Running the Django Server in "Production"

By default docker-compose will look for a docker-compose.yml for instructions of what to do. This file is the development (and thus default) config for docker-compose.

If you'd like to run the project with a more production-like setup, you can specify the docker-compose.prod.yml file. This setup copies the project code in (instead of mirroring) and uses nginx with uwsgi to run django.

If you are using the production setup and you have made changes you wish to see reflected in the running container, you will need to stop and then rebuild the production containers:

Deployment

To get the image on the prod server, simply update the release branch and push it to github. The rest should happen automatically (thanks to github actions and watchtower keeping the deployed image up to date).

Accessing the Django Server Running in Docker

The development server will be reachable on port 8000:

The production server will be reachable on port 8080:

There are various examples of URLs in this readme and they all feature the development port. You will need to adjust that if you are using the production server.

First Time Setup

Badgr App Configuration

If your badgr-ui is running on http://localhost:4000, use the following values:

Authentication Configuration

OIDC authentication

If you set up the Additional configuration options (or at least the parts relevant for OIDC authentication), you shouldn't have to configure anything else; the "Anmelden mit Mein Bildungsraum" button should work out of the box. Do note that the OIDC authentication mechanism produces access tokens that, in contrast to the ones we generate ourselves, aren't restricted to any scopes. They can thus access anything on the page not limited to admin / superuser users. This also is the default behavior for the tokens we generate ourselves.

Run the tests

For the tests to run you first need to run docker (docker-compose up). Then within docker, run tox: docker-compose exec api tox. Note that you might have to run docker-compose build once for the new changes to the testing enviornment to take effect. To just run a single test:

docker-compose exec api python /badgr_server/manage.py test -k <test-name>
# Example:
docker-compose exec api python /badgr_server/manage.py test issuer.tests.test_issuer.IssuerTests.test_cant_create_issuer_with_unverified_email_v1

Debug

For debugging, in the Docerfile.dev.api debugpy is also installed and there is the docker compose file docker-compose.debug.yml. In VSCode you can create a launch.json by choosing Python as debugger and Remote Attach as debug configuration (and defaults for the rest). You can then start the application with

docker compose -f docker-compose.yml -f docker-compose.debug.yml up

and attach the debugger in VSCode by selecting Python: Remote Attach. This process is heavily inspired by this tutorial.

Install and run Badgr UI {#badgr-ui}

Start in your badgr directory and clone badgr-ui source code: git clone https://github.com/concentricsky/badgr-ui.git badgr-ui

For more details view the Readme for Badgr UI.

Code Quality

To ensure consistency and quality in code contributions, we use pre-commit hooks to adhere to commit message conventions and code quality guidelines. Follow these steps to set up your development environment:

Make sure you have pre-commit installed on your machine. You can install it using pip:

pip install pre-commit

Navigate to the root directory of the repository and run the following command to initialize pre-commit hooks:

pre-commit install

This command sets up the pre-commit hooks defined in the pre-commit-config.yaml file.

To run the configured hooks on some / all files of the project run:

pre-commit run --files <file-name>
pre-commit run --all-files

You will also need to have commitizen installed, e.g. via

pip install commitizen