Badgr integration updates
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.
An Issuer App is needed, either registered at https://badgr.org/app-developers/#issuer-apps or in your own instance of the Badgr Server.
in `studio.yml` and `lms.yml`:
BADGR_USERNAME = "email@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>"
PR for updating the documentation to match these changes: https://github.com/edx/edx-documentation/pull/1927
Heads up this is going your way once tests are green.