Package: edx-auth-backends
auth-backendsThis package contains custom authentication backends, views, and pipeline steps used by edX services for single sign-on.This package is compatible with Python 3.8, Django 2.2 and Django 3.0We currently support OAuth 2.0 authentication. Support for OpenID Connect (OIDC) was removed as of version 3.0. Use version 2.x if you require OIDC and are not able to migrate to OAuth2.InstallationTheauth_backendspackage can be installed from PyPI using pip:$ pip install edx-auth-backendsUpdateINSTALLED_APPS:INSTALLED_APPS=('social_django',)ConfigurationAdding single sign-on/out support to a service requires a few changes:Define settingsAdd the authentication backendAdd the login/logout redirectsOAuth 2.0 SettingsSettingPurposeSOCIAL_AUTH_EDX_OAUTH2_KEYClient keySOCIAL_AUTH_EDX_OAUTH2_SECRETClient secretSOCIAL_AUTH_EDX_OAUTH2_URL_ROOTLMS root, reachable from the application server
(e.g.https://courses.stage.edx.orgorhttp://edx.devstack.lms:18000)SOCIAL_AUTH_EDX_OAUTH2_PUBLIC_URL_ROOTLMS root, reachable from the end user’s browser
(e.g.https://courses.stage.edx.orgorhttp://localhost:18000)SOCIAL_AUTH_EDX_OAUTH2_JWS_HMAC_SIGNING_KEY(Optional) Shared secret for JWT signed with HS512 algorithmSOCIAL_AUTH_EDX_OAUTH2_PROVIDER_CONFIGURATION_CACHE_TTL(Optional) Cache timeout for provider configuration. Defaults to 1 week.SOCIAL_AUTH_EDX_OAUTH2_JWKS_CACHE_TTL(Optional) Cache timeout for provider’s JWKS key data. Defaults to 1 day.OAuth2 Applications require access to theuser_idscope in order for theEdXOAuth2backend to work.  The backend will write theuser_idinto the social-auth extra_data, and can be accessed within the User model as follows:self.social_auth.first().extra_data[u'user_id']  # pylint: disable=no-memberStrategyWe use a customstrategythat includes many of
the default settings necessary to utilize single sign-on for edX services. This strategy should be used for all
services to simplify configuration. If you need to override the defaults, you may still do so as you would with any
social auth setting——prependSOCIAL_AUTH_to the setting name. Add the following to your Django settings to use the
strategy:SOCIAL_AUTH_STRATEGY='auth_backends.strategies.EdxDjangoStrategy'Authentication BackendConfiguring the backend is simply a matter of updating theAUTHENTICATION_BACKENDSsetting. The configuration
below is sufficient for all edX services.AUTHENTICATION_BACKENDS=('auth_backends.backends.EdXOAuth2','django.contrib.auth.backends.ModelBackend',)Authentication ViewsIn order to make use of the authentication backend, your service’s login/logout views need to be updated. The login
view should be updated to redirect to the authentication provider’s login page. The logout view should be updated to
redirect to the authentication provider’s logout page.This package includes views and urlpatterns configured for OAuth 2.0. To use them, simply append/prependoauth2_urlpatternsto your service’s urlpatterns inurls.py.fromauth_backends.urlsimportoauth2_urlpatternsurlpatterns=oauth2_urlpatterns+[url(r'^admin/',include(admin.site.urls)),...]It is recommended that you not modify the login view. If, however, you need to modify the logout view (to redirect to
a different URL, for example), you can subclassEdxOAuth2LogoutViewfor
the view andLogoutViewTestMixinfor your tests.TestingCallmake test.Publishing a ReleaseAfter a PR merges, create a new tag frommasterbranch with a new version of the package and create aGithub releaseusing the new tag that will automatically publish the package to PyPi when a release is created.LicenseThe code in this repository is licensed under the AGPL unless otherwise noted.Please seeLICENSE.txtfor details.How To ContributeContributions are very welcome!Please readHow To Contributefor details.Reporting Security IssuesPlease do not report security issues in public. Please emailsecurity@edx.org.Mailing List and IRC ChannelYou can discuss this code on theedx-code Google Groupor in the#edx-codeIRC channel on Freenode.History3.1.0 (2020-05-08)Added support for python 3.8Removed support for Django versions older than 2.23.0.2 (2020-02-06)Re-release of 3.0.0 with proper version, matching tag.3.0.1 (2020-02-06)Re-release of 3.0.0, although failed to update package version.3.0.0 (2020-02-06)Add support for Django 2 and drop support for some older versions (support changes from 1.8–1.11 to 1.11–2.2)Remove (deprecated) OpenID Connect supportTest with Python 3.5, not 3.6, to match rest of edX code2.0.2 (2019-08-12)Two new commits that changed functionality:Add EdXOAuth2.auth_complete_signal on auth_complete()Store refresh_token in extra_data2.0.1 (2019-05-13)Create new Version for auth-backends for release2.0.0 (2019-03-28)EdXOAuth2 will retrieve and store user_id claimThe EdXOAuth2 backend will now pull the user_id from the JWT and
store it in the UserSocialAuth.extra_data field.BREAKING CHANGE: The user_id scope is now required when using the
EdXOAuth2 backend for oAuth+SSO. This means that the oauth
application must first be configured to have access to the user_id
scope, which is not available by default.1.2.2 (2019-01-31)Updates to the EdXOAuth2 backend:Supports the _PUBLIC_URL_ROOT social django setting.logout_url() allows _LOGOUT_REDIRECT_URL to be undefined.1.2.1 (2018-10-26)Fix urlencode bug with EdXOAuth2 backend logout url1.2.0 (2018-10-26)Allow for logout redirect with EdXOAuth2 backend.1.1.5 (2018-10-19)Add logout_url property to EdXOAuth2 backend.1.1.4 (2018-10-12)Remove token validation from EdXOAuth2 backend.1.1.3 (2018-01-04)Added support to update email address.social_core consider email field protected and won’t let it change.
Added a pipeline function to update email address.1.1.2 (2017-05-12)Updated LoginRedirectBaseView to include querystring[unlisted]Intervening releases not documented here; see Releases:https://github.com/openedx/auth-backends/releases?after=1.1.20.1.3 (2015-03-31)Update required version of Python Social Auth to 0.2.3.0.1.2 (2015-02-23)Update required version of Python Social Auth to 0.2.2.0.1.1 (2015-02-20)Initial release.Renzo Lucioni <renzo@edx.org>
Troy Sankey <tsankey@edx.org>