Skip to main content

auth-backends Travis Codecov

This repo houses a custom authentication backend, views, and pipeline steps used by edX services for single sign-on. This functionality is built atop the OpenID Connect (OIDC) protocol.

This package is compatible with Python 2.7 and 3.5, and Django 1.8 and 1.9.

Installation

The auth_backends package can be installed from PyPI using pip:

$ pip install edx-auth-backends

Configuration

Adding single sign-on/out support to a service requires a few changes:

  1. Define settings

  2. Add the authentication backend

  3. Add the login/logout redirects

Settings

The following settings MUST be set:

Setting

Purpose

SOCIAL_AUTH_EDX_OIDC_KEY

OAuth/OpenID Connect client key

SOCIAL_AUTH_EDX_OIDC_SECRET

OAuth/OpenID Connect client secret

SOCIAL_AUTH_EDX_OIDC_ID_TOKEN_DECRYPTION_KEY

Identity token decryption key (same value as the client secret for edX OpenID Connect)

SOCIAL_AUTH_EDX_OIDC_URL_ROOT

OAuth/OpenID Connect provider root (e.g. https://courses.stage.edx.org/oauth2)

SOCIAL_AUTH_EDX_OIDC_LOGOUT_URL

OAuth/OpenID Connect provider’s logout page URL (e.g. https://courses.stage.edx.org/logout)

SOCIAL_AUTH_STRATEGY

Python Social Auth strategy. Set this to ‘auth_backends.strategies.EdxDjangoStrategy’

If your application requires additional user data in the identity token, you can specify additional claims by defining the EXTRA_SCOPE setting. For example, if you wish to have a claim named preferred_language, you would include the following in your settings:

EXTRA_SCOPE = ['preferred_language']

Assuming the identity provider knows how to process that scope, the associated claim data will be included in the identity token returned during authentication. Note that these scopes/claims are dependent on the identity provider being used. The EdXOpenIdConnect backend is configured to be used by all edX services out-of-the-box.

The optional setting COURSE_PERMISSIONS_CLAIMS, used primarily by edx-analytics-dashboard, can be used to designate scopes/claims that should be requested in order to retrieve a list of courses the user is permitted to access/administer. The value of this array depends on the authentication provider’s available scopes.

Strategy

We use a custom strategy that 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——prepend SOCIAL_AUTH_ to the setting name. Add the following to your Django settings to use the strategy:

SOCIAL_AUTH_STRATEGY = 'auth_backends.strategies.EdxDjangoStrategy'

Authentication Backend

Configuring the backend is simply a matter of updating the AUTHENTICATION_BACKENDS setting. The configuration below is sufficient for all edX services.

AUTHENTICATION_BACKENDS = (
    'auth_backends.backends.EdXOpenIdConnect',
    'django.contrib.auth.backends.ModelBackend',
)

Authentication Views

In 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 OpenID Connect provider’s login page. The logout view should be updated to redirect to the OpenID Connect provider’s logout page.

This package includes views and urlpatterns configured for edX OpenID Connect. To use them, simply append/prepend auth_urlpatterns to your service’s urlpatterns in urls.py.

from auth_backends.urls import auth_urlpatterns

urlpatterns = auth_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 subclass EdxOpenIdConnectLogoutView for the view and LogoutViewTestMixin for your tests.

Devstack

When using the Docker-based devstack, it is necessary to have both internal and public URLs for the OAuth/OIDC provider. To accommodate this need, set the SOCIAL_AUTH_EDX_OIDC_PUBLIC_URL_ROOT setting to the value of the provider’s browser-accessible URL.

SOCIAL_AUTH_EDX_OIDC_URL_ROOT = 'http://edx.devstack.edxapp:18000/oauth2'
SOCIAL_AUTH_EDX_OIDC_PUBLIC_URL_ROOT = 'http://localhost:18000/oauth2'

Additionally, the logout URL should also be browser-accessible:

SOCIAL_AUTH_EDX_OIDC_LOGOUT_URL = 'http://localhost:18000/logout'

Testing

Call make test.

License

The code in this repository is licensed under the AGPL unless otherwise noted.

Please see LICENSE.txt for details.

How To Contribute

Contributions are very welcome!

Please read How To Contribute for details.

Even though it was written with edx-platform in mind, the guidelines should be followed for Open edX code in general.

Reporting Security Issues

Please do not report security issues in public. Please email security@edx.org.

Mailing List and IRC Channel

You can discuss this code on the edx-code Google Group or in the #edx-code IRC channel on Freenode.

History

0.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>

Metadata

Release files for edx-auth-backends 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for edx-auth-backends 0.7.0
File Size Uploaded
edx-auth-backends-0.7.0.tar.gz 25.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for edx-auth-backends 0.7.0
File Interpreter ABI Platform
edx_auth_backends-0.7.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 44.1 kB

Release files / edx-auth-backends-0.7.0.tar.gz

Download URL edx-auth-backends-0.7.0.tar.gz
Size 25.7 kB
Tags Source
SHA-256 checksum
How to use checksums
181b0c9d9c544b926666d45d2482d443e3965bd05a0e626ce6e60517f2f31202
BLAKE2b-256 checksum
How to use checksums
1ff928501571a0cf60313eec6fa90bda1ab4d1b105a01c7e05b4587e03003e4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / edx_auth_backends-0.7.0-py2.py3-none-any.whl

Download URL edx_auth_backends-0.7.0-py2.py3-none-any.whl
Size 18.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
d08f0ac28fa123e635c60a25d637b30072614e8b49f052f78882d8c582e1ddae
BLAKE2b-256 checksum
How to use checksums
cf9036c390935b10a503ce8435d92c15436ec9b425dd8fb2a2cd34d157ecea85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

5.1.0

2 release files

5.0.0

2 release files

4.6.2

2 release files

4.6.1

2 release files

4.6.0

2 release files

4.5.0

2 release files

4.4.0

2 release files

4.3.0

2 release files

4.2.0

2 release files

4.1.0

2 release files

4.0.1

2 release files

4.0.0

2 release files

3.4.0

2 release files

3.3.3

2 release files

3.3.2

2 release files

3.3.1

2 release files

3.3.0

2 release files

3.1.0

2 release files

3.0.2

2 release files

3.0.0

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

This release

0.7.0 This release

2 release files

0.6.0

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page