mrtmm
(Maari Tamm)
July 21, 2021, 6:53am
1
Hi Folks!
The Badgr integration has been broken for quite a while. The long-lived tokens are no longer supported by Badgr and the support for v1 API is coming to an end soon as well. I’ve been working on the updates to fix the integration and these changes have now landed in master:
edx:master
← mrtmm:badgr-integration-updates
opened 08:43AM - 30 Mar 21 UTC
## Description
The Badgr integration at its current state is broken and it wo… uld 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.
## 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>"
```
## Documentation
PR for updating the documentation to match these changes: https://github.com/edx/edx-documentation/pull/1927
edx:master
← mrtmm:badge-assertion-data-update
opened 02:37PM - 25 Jun 21 UTC
* Fix retrieving BadgeAssertion data from Badgr
With edx#27181, the integration… with Badgr was updated and fixed to
be working with the Badgr v2 API. However, retrieving the badge assertion
data from Badgr still needs to be updated for the new json response
structure so we can save it at our end as well.
* Add BadgeAssertion table to LMS admin
Adding BadgeAssertion table to LMS admin is merely a suggestion
as I found it very helpful when configuring and testing the backend integration.
So this might be generally helpful for operators but I am happy to drop
this commit if there is any objections.
## Testing instructions
Same as for #27181
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>"
```
Noticeable result when applying this patch is that one can properly see the badge image under profile -> accomplishments, since the image url and other data about the badge assertion will then be properly retrieved from Badgr and saved.
I’d love to see these changes in Lilac as well, here’s the PR:
edx:open-release/lilac.master
← mrtmm:badgr-integration-updates-lilac
opened 06:53AM - 19 Jul 21 UTC
**Badgr integration updates (#27181)**
* Badgr integration fix
Bad… ges are no longer created on the Badgr side with a given
'slug'. Instead, a slug(v1) or an entityId(v2) will be generated
for each badge on the Badgr side and we will need to use that
value to check if a certain badge matching a BadgeClass on our side
exists and/or to create assertions for it.
This commit introduces a new field to the badgeclass:
'badgr_server_slug' by cherry-picking the following commit from
3309aab2a2eb00d28c5ca3d3145c8dddb15e6159
- TTK-18543: fix Badgr Server
connection (https://github.com/teltek/edx-platform/pull/46)
This commit also modifies the cherry-picked commit by making the newly
added field optional since the BadgeClass is not neccessarily always used
with the Badgr backend.
Co-authored-by: mrey <mrey@teltek.es>
* Implement OAuth2 tokens flow for BadgrBackend
* Use Badgr v2 API
Co-authored-by: mrey <mrey@teltek.es>
(Cherry-Picked from a0165e88b2d3ac37651f415690183187d628e676)
**Fix retrieving BadgeAssertion data from Badgr (#28039)**
* Fix retrieving BadgeAssertion data from Badgr
With edx#27181, the integration with Badgr was updated and fixed to
be working with the Badgr v2 API. However, retrieving the Badge Assertion
data from Badgr still needs to be updated for the new json response
structure so we can save it at our end as well.
* Add BadgeAssertion table to LMS admin
It is not a small patch so I do understand the concern. However, I wouldn’t call it a new feature as well since it is actually fixing something that has been broken for a long time. I believe adding this change would only affect folks that have badging enabled and I am not sure how many there are. I didn’t get any responses about it in slack .
I’d love to get your thoughts on adding this to Lilac, I’m here for any questions and concerns
Thanks!
4 Likes