{"id":20037808,"url":"https://github.com/openedx/auth-backends","last_synced_at":"2025-04-04T14:06:27.952Z","repository":{"id":27453913,"uuid":"30932613","full_name":"openedx/auth-backends","owner":"openedx","description":"Custom authentication backends and views for edX services","archived":false,"fork":false,"pushed_at":"2025-03-27T02:32:25.000Z","size":414,"stargazers_count":22,"open_issues_count":3,"forks_count":18,"subscribers_count":116,"default_branch":"master","last_synced_at":"2025-03-28T13:07:19.599Z","etag":null,"topics":["authentication","edx","oauth2","oidc","openid-connect","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openedx.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-02-17T19:08:53.000Z","updated_at":"2025-03-20T09:10:24.000Z","dependencies_parsed_at":"2023-02-10T19:46:26.445Z","dependency_job_id":"c9478b6c-1e87-4081-98c3-ea66bef298b0","html_url":"https://github.com/openedx/auth-backends","commit_stats":{"total_commits":256,"total_committers":40,"mean_commits":6.4,"dds":0.49609375,"last_synced_commit":"7c54313e7fe8eb900d8da7a64995014e2dc08e4f"},"previous_names":["edx/auth-backends"],"tags_count":47,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openedx%2Fauth-backends","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openedx%2Fauth-backends/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openedx%2Fauth-backends/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openedx%2Fauth-backends/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openedx","download_url":"https://codeload.github.com/openedx/auth-backends/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247190231,"owners_count":20898700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","edx","oauth2","oidc","openid-connect","python"],"created_at":"2024-11-13T10:22:37.466Z","updated_at":"2025-04-04T14:06:27.934Z","avatar_url":"https://github.com/openedx.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"auth-backends  |CI|_ |Codecov|_\n===================================\n.. |CI| image:: https://github.com/openedx/auth-backends/workflows/Python%20CI/badge.svg?branch=master\n.. _CI: https://github.com/openedx/auth-backends/actions?query=workflow%3A%22Python+CI%22\n\n.. |Codecov| image:: http://codecov.io/github/edx/auth-backends/coverage.svg?branch=master\n.. _Codecov: http://codecov.io/github/edx/auth-backends?branch=master\n\nThis package contains custom authentication backends, views, and pipeline steps used by edX services for single sign-on.\n\nThis package is compatible with Python 3.8, Django 2.2 and Django 3.0\n\nWe 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.\n\nInstallation\n------------\n\nThe `auth_backends` package can be installed from PyPI using pip::\n\n    $ pip install edx-auth-backends\n\nUpdate ``INSTALLED_APPS``:\n\n.. code-block:: python\n\n    INSTALLED_APPS = (\n        'social_django',\n    )\n\n\nConfiguration\n-------------\nAdding single sign-on/out support to a service requires a few changes:\n\n1. Define settings\n2. Add the authentication backend\n3. Add the login/logout redirects\n\n\nOAuth 2.0 Settings\n~~~~~~~~~~~~~~~~~~\n+----------------------------------------------------------+-------------------------------------------------------------------------------------------+\n| Setting                                                  | Purpose                                                                                   |\n+==========================================================+===========================================================================================+\n| SOCIAL_AUTH_EDX_OAUTH2_KEY                               | Client key                                                                                |\n+----------------------------------------------------------+-------------------------------------------------------------------------------------------+\n| SOCIAL_AUTH_EDX_OAUTH2_SECRET                            | Client secret                                                                             |\n+----------------------------------------------------------+-------------------------------------------------------------------------------------------+\n| SOCIAL_AUTH_EDX_OAUTH2_URL_ROOT                          | LMS root, reachable from the application server                                           |\n|                                                          | (e.g. https://courses.stage.edx.org or http://edx.devstack.lms:18000)                     |\n+----------------------------------------------------------+-------------------------------------------------------------------------------------------+\n| SOCIAL_AUTH_EDX_OAUTH2_PUBLIC_URL_ROOT                   | LMS root, reachable from the end user's browser                                           |\n|                                                          | (e.g. https://courses.stage.edx.org or http://localhost:18000)                            |\n+----------------------------------------------------------+-------------------------------------------------------------------------------------------+\n| SOCIAL_AUTH_EDX_OAUTH2_JWS_HMAC_SIGNING_KEY              | (Optional) Shared secret for JWT signed with HS512 algorithm                              |\n+----------------------------------------------------------+-------------------------------------------------------------------------------------------+\n| SOCIAL_AUTH_EDX_OAUTH2_PROVIDER_CONFIGURATION_CACHE_TTL  | (Optional) Cache timeout for provider configuration. Defaults to 1 week.                  |\n+----------------------------------------------------------+-------------------------------------------------------------------------------------------+\n| SOCIAL_AUTH_EDX_OAUTH2_JWKS_CACHE_TTL                    | (Optional) Cache timeout for provider's JWKS key data. Defaults to 1 day.                 |\n+----------------------------------------------------------+-------------------------------------------------------------------------------------------+\n\nOAuth2 Applications require access to the ``user_id`` scope in order for the ``EdXOAuth2`` backend to work.  The backend will write the ``user_id`` into the social-auth extra_data, and can be accessed within the User model as follows::\n\n    self.social_auth.first().extra_data[u'user_id']  # pylint: disable=no-member\n\nStrategy\n~~~~~~~~\nWe use a custom `strategy \u003chttp://python-social-auth.readthedocs.io/en/latest/strategies.html\u003e`_ that includes many of\nthe default settings necessary to utilize single sign-on for edX services. This strategy should be used for all\nservices to simplify configuration. If you need to override the defaults, you may still do so as you would with any\nsocial auth setting——prepend `SOCIAL_AUTH_` to the setting name. Add the following to your Django settings to use the\nstrategy:\n\n.. code-block:: python\n\n    SOCIAL_AUTH_STRATEGY = 'auth_backends.strategies.EdxDjangoStrategy'\n\nAuthentication Backend\n~~~~~~~~~~~~~~~~~~~~~~\nConfiguring the backend is simply a matter of updating the ``AUTHENTICATION_BACKENDS`` setting. The configuration\nbelow is sufficient for all edX services.\n\n.. code-block:: python\n\n    AUTHENTICATION_BACKENDS = (\n        'auth_backends.backends.EdXOAuth2',\n        'django.contrib.auth.backends.ModelBackend',\n    )\n\nAuthentication Views\n~~~~~~~~~~~~~~~~~~~~\nIn order to make use of the authentication backend, your service's login/logout views need to be updated. The login\nview should be updated to redirect to the authentication provider's login page. The logout view should be updated to\nredirect to the authentication provider's logout page.\n\nThis package includes views and urlpatterns configured for OAuth 2.0. To use them, simply append/prepend\n``oauth2_urlpatterns`` to your service's urlpatterns in `urls.py`.\n\n.. code-block:: python\n\n    from auth_backends.urls import oauth2_urlpatterns\n\n    urlpatterns = oauth2_urlpatterns + [\n        url(r'^admin/', include(admin.site.urls)),\n        ...\n    ]\n\nIt is recommended that you not modify the login view. If, however, you need to modify the logout view (to redirect to\na different URL, for example), you can subclass ``EdxOAuth2LogoutView`` for\nthe view and ``LogoutViewTestMixin`` for your tests.\n\nTesting\n-------\n\nCall ``make test``.\n\nPublishing a Release\n--------------------\n\nAfter a PR merges, create a new tag from ``master`` branch with a new version of the package and create a\n`Github release \u003chttps://github.com/openedx/auth-backends/releases\u003e`_\nusing the new tag that will automatically publish the package to PyPi when a release is created.\n\n\nLicense\n-------\n\nThe code in this repository is licensed under the AGPL unless otherwise noted.\n\nPlease see ``LICENSE.txt`` for details.\n\nHow To Contribute\n-----------------\n\nContributions are very welcome!\n\nPlease read `How To Contribute \u003chttps://github.com/openedx/.github/blob/master/CONTRIBUTING.md\u003e`_ for details.\n\nReporting Security Issues\n-------------------------\n\nPlease do not report security issues in public. Please email security@openedx.org.\n\nMailing List and IRC Channel\n----------------------------\n\nYou can discuss this code on the `edx-code Google Group \u003chttps://groups.google.com/forum/#!forum/edx-code\u003e`_ or in the\n``#edx-code`` IRC channel on Freenode.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenedx%2Fauth-backends","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenedx%2Fauth-backends","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenedx%2Fauth-backends/lists"}