Wednesday, July 9, 2014

edx-platform - Why didn't the THIRD_PARTY_AUTH feature work for me?

Yesterday, I's trying to enable the THIRD_PARTY_AUTH feature of the OpenEdX following these article of the author:

Overview of the feature:
http://johnmcox.blogspot.com/2014/05/getting-started-with-edx-third-party.html

To understand how the feature works in OpenEdX:
http://johnmcox.blogspot.com/2014/05/understanding-edx-third-party.html

I did everything the author said to enable the third party authentication feature to allow my users at UnSchool using their GMail or LinkedIn account to log in to our OpenEdX, including:

1. I did enable the feature in the /edx/app/edxapp/lms.env.json:

...
    "FEATURES": {
        "ENABLE_THIRD_PARTY_AUTH": true,
        "AUTH_USE_OPENID_PROVIDER": true,
        "AUTOMATIC_AUTH_FOR_TESTING": false,

...

2. Create Google and LinkedIn apps, then fill in the /edx/app/edxapp/lms.auth.json with keys and secrets of these apps (at the end of the json):

...
    "THIRD_PARTY_AUTH": {
        "Google": {
            "SOCIAL_AUTH_GOOGLE_OAUTH2_KEY": "<google app client ID>",
            "SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET": "<google app secret>"
        },
        "LinkedIn": {
            "SOCIAL_AUTH_LINKEDIN_OAUTH2_KEY": "<LinkedIn app API key>",
            "SOCIAL_AUTH_LINKEDIN_OAUTH2_SECRET": "<LnkedIn app secret>"
        }
    }
...

3. Run the database update:

$ sudo -H -u edxapp bash
$ source /edx/app/edxapp/edxapp_env
$ paver update_db --settings=aws

And the results is:



The Google and LinkedIn buttons appeared in register and login page. But, the problem was, when I clicked to those buttons, the system said "Page not found".

What happened?

I's asking around the edx-code mailing list and got helps from the author of the feature, John Cox:

https://groups.google.com/d/msg/edx-code/b1ccc6dJ6ZE/0MTkWKf08i0J

As he suggested that maybe there was something wrong with my configuration or settings, because the third_party_auth app should had taken care of the settings for me (/edx/app/edxapp/edx-platform/common/djangoapps/third_party_auth/settings.py):

...
    # Register and configure python-social-auth with Django.
    django_settings.INSTALLED_APPS += (
        'social.apps.django_app.default',
        'third_party_auth',
    )
...

Then I checked my edx-platform settings again (/edx/app/edxapp/edx-platform/lms/env/common.py), I included the 'social.apps.django_app.default' app before hand:

...
INSTALLED_APPS = (
    ...
    'social.apps.django_app.default', 

    'edx_sga'
)
...


I did that because of a bug 2 months ago https://github.com/edx/edx-platform/issues/3639 when I hadn't enable this authentication feature yet.

Now, I just remove that app (social.apps.django_app.default) from INSTALLED_APP and restart the services. Everything is working now.