Can't enable keycloak OAuth2 backend with YML plugin

Hello I’m trying to enable OAuth2 authentication using Keycloak backend of python-social-auth.

I’m following this section of the Open EdX doc where I need to specify the keycloak backend in the lms.yml

To modify the lms.yml of Open EdX, I’ve made a tutor YAML plugin but I’m getting an error when I do tutor config save.

This is the content of my YAML file

name : auth
version : 0.1.0
patches :
        common-env-feature:
                "ENABLE_THIRD_PARTY_AUTH" : true 

        lms-env:
                "THIRD_PARTY_AUTH_BACKENDS" : ["social_core.backends.keycloak.KeycloakOAuth2"]

And this is the stacktrace I get after tutor config save

It indicate that an error is thrown because of the lms-env section of the YML but I don’t see mistake in it.

What am I doing wrong ?

Thanks a lot for your help.

Ha! That’s a good one. I should keep it as a quiz question for future interviews with project @maintainers :slight_smile:

Can someone spot the mistake here? Bonus question: how could we improve the error log such that future developers don’t fall in the same trap?

Click to reveal the solution

The problem is that in your yaml file the patches are dict entries, and not strings. To write these values as strings, you must add a multiline character “|” for every patch:

patches :
        common-env-features: |
                "ENABLE_THIRD_PARTY_AUTH" : true 

        lms-env: |
                "THIRD_PARTY_AUTH_BACKENDS" : ["social_core.backends.keycloak.KeycloakOAuth2"]

To improve the error log, we should check that patch entries are actually strings, or convert them so strings.

It might be surprising that Tutor fails with this error despite the recent introduction of type annotations. In this particular case, the error is ignore because of a cast(...) statement, which goes to show how harmful type casting can be.

EDIT: as a side note, the “common-env-feature” patch should be renamed to “common-env-features”.

Thank you for you reactive answer !

However, I still have the same stack trace, even after escaping the quote or replacing by single quote :confused:

What am I missing ?

name : auth
version : 0.1.0
patches :
        common-env-feature:
                "ENABLE_THIRD_PARTY_AUTH" : true 

        lms-env:
                "THIRD_PARTY_AUTH_BACKENDS" : "['social_core.backends.keycloak.KeycloakOAuth2']"

I just changed “common-env-feature” to “common-env-features ” and now i’ve this stacktrace :

Are you quite sure that you are editing the file in $(tutor plugins printroot)/ and not your original yaml file? The plugin.yml file is copied to this directory when you run tutor plugins install and gets loaded from there.

Yes I am sure that I am editing from $(tutor plugins printroot) (which is /home/ippon/.local/share/tutor-plugins).

If it wasn’t the case the stackstrace would have not change when I changed “common-env-feature” to “common-env-features” (as you can see in my third answer). It didn’t throw an error in the first case because I mispelled it.

See my edited answer: the problem is actually that your entire patches should be strings, not dicts.

It works ! Thank you for your help :slight_smile: