Badgr integration updates

Description

  1.  

    1. Description

The Badgr integration at its current state is broken and it would be great if we could fix it. This PR holds commits for that purpose.

For a while now, it is not possible to create a badge on the Badgr side with a `slug` that we provide. Instead a `slug` (Badgr API v1) or an `entityId` (Badgr API v2) is created for each badge on the Badgr side and we will need to know about it in order to check if a certain badge exists or to create assertions for one.
A proposed fix for this is to cherry-pick a commit (from 3309aab2a2eb00d28c5ca3d3145c8dddb15e6159) to introduce a new field to the BadgeClass model: `badgr_server_slug` that will store this value for us.
However, I've modified that commit by making this field optional since Badgr is not the only backend that can be used for badging.

The long-lived access tokens are no longer supported by Badgr. Instead, we'll need to implement the flow of creating and refreshing the access tokens that are valid for 24h. This PR proposes the changes to implement this flow. With this change the necessary values for creating tokens should be configured in `lms.yml`. The tokens will be then created or refreshed on the go as needed and stored in cache.

The Badgr API v1 will likely reach end-of-life in Q4 2021 so we'd probably want to make the switch to API v2 as well.

  1.  

    1. Testing instructions

Prerequisites:

An Issuer App is needed, either registered at https://badgr.org/app-developers/#issuer-apps or in your own instance of the Badgr Server.

Configuration examples:

in `studio.yml` and `lms.yml`:
```
FEATURES:
ENABLE_OPENBADGES: true
```

in `lms.yml`:
```
BADGR_USERNAME = "example@example.com"
BADGR_PASSWORD = "password"
BADGR_TOKENS_CACHE_KEY = "secret-cache-key"
BADGR_BASE_URL = "http://localhost:8005"
BADGR_ISSUER_SLUG = "issuer-slug"
```

Make sure your Issuer App is configured properly, you can test creating and refreshing tokens as noted in https://api.badgr.io/docs/v2/ :

```
curl -X POST '$BADGR_BASE_URL/o/token' -d "username=$BADGR_USERNAME&password=$BADGR_PASSWORD"
```
```
curl -X POST '$BADGR_BASE_URL/o/token' -d "grant_type=refresh_token&refresh_token=<refresh_token>"
```

  1.  

    1. Documentation

PR for updating the documentation to match these changes: https://github.com/edx/edx-documentation/pull/1927

Activity

Show:
Natalia Berdnikov
April 2, 2021, 2:31 PM

Heads up this is going your way once tests are green.

Your pinned fields
Click on the next to a field label to start pinning.

Assignee

Wajeeha Khalid

Reporter

Open Source Pull Request Bot

Labels

Contributor Name

Maari

Repo

edx/edx-platform

Github Lines Added

317

Github Lines Deleted

45