Skip to content

Convert errors from django_openid_auth to python-social-auth with Launchpad backend#14

Merged
Hyask merged 2 commits intomainfrom
copilot/convert-errors-to-django-oauth-toolkit
Mar 12, 2026
Merged

Convert errors from django_openid_auth to python-social-auth with Launchpad backend#14
Hyask merged 2 commits intomainfrom
copilot/convert-errors-to-django-oauth-toolkit

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 3, 2026

django_openid_auth is deprecated. Replace it with python-social-auth (social-auth-app-django), which provides a built-in LaunchpadOpenId backend that handles authentication via login.launchpad.net out of the box.

Changes

  • settings.py: OpenIDBackendLaunchpadOpenId, social_django in INSTALLED_APPS, all OPENID_* settings removed, LOGIN_URL/login/launchpad/, SOCIAL_AUTH_LOGIN_ERROR_URL/login-failed
  • urls.py: social_django.urls mounted at /login/ (provides /login/launchpad/ and /login/complete/launchpad/), removed stale commented-out django_openid_auth URL
  • config.py: Removed unused openid_trust_root setting
  • pyproject.toml: Added social-auth-app-django>=5.0.0 to dev deps

Removed

  • All OPENID_* settings (no longer needed)
  • OPENID_LAUNCHPAD_TEAMS_MAPPING (Launchpad team-to-group mapping dropped)
  • openid_trust_root from config.py
  • Custom backends.py and oidc.py from previous iterations

Unchanged

  • auth.py group-based authorization (@can_see_stacktraces) — uses Django groups, backend-agnostic
  • logout_view / login_failed views
  • context_processors.py — builds login URL from settings.LOGIN_URL
  • index.html — login.ubuntu.com profile link preserved

Deployment note

No special configuration is required beyond installing the social-auth-app-django package and running migrations for social_django. The LaunchpadOpenId backend authenticates users via login.launchpad.net using OpenID 2.0 without needing client credentials.

Original prompt

This section details on the original issue you should resolve

<issue_title>Convert errors to using django-oauth-toolkit</issue_title>
<issue_description>The errors Django app is currently relying on the django_openid_auth plugin, but this plugin is deprecated. We should transition to django-oauth-toolkit, which is more modern and maintained, and provides OpenID Connect just fine: https://django-oauth-toolkit.readthedocs.io/en/stable/oidc.html</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Convert errors to use django-oauth-toolkit Convert errors from django_openid_auth to django-oauth-toolkit Mar 3, 2026
Copilot finished work on behalf of Hyask March 3, 2026 17:11
@Hyask
Copy link
Copy Markdown
Collaborator

Hyask commented Mar 3, 2026

@copilot the new workflow should still rely on the SSO provided by login.ubuntu.com, as before.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 3, 2026

@copilot the new workflow should still rely on the SSO provided by login.ubuntu.com, as before.

Reworked in f851b5f. The authentication flow now uses login.ubuntu.com as the OIDC provider:

  1. /oidc/login/ redirects to login.ubuntu.com's OIDC authorize endpoint
  2. /oidc/callback/ handles the callback — exchanges the authorization code for tokens, fetches userinfo, creates/updates the Django user, and maps Launchpad teams to Django groups (preserved as OIDC_LAUNCHPAD_TEAMS_MAPPING)
  3. The login.ubuntu.com profile link in the template is restored

OIDC endpoint URLs default to login.ubuntu.com/+openid-connect/* in config.py. Operators need to set oidc_client_id and oidc_client_secret in local_config.py.

Copilot AI changed the title Convert errors from django_openid_auth to django-oauth-toolkit Convert errors from django_openid_auth to django-oauth-toolkit with login.ubuntu.com OIDC SSO Mar 3, 2026
Copilot finished work on behalf of Hyask March 3, 2026 17:22
Comment thread src/errors/oidc.py Outdated
@@ -0,0 +1,149 @@
import logging
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot don't re-implement oidc yourself, but just make use of django-oauth-toolkit, and configure it appropriately use login.ubuntu.com as the OIDC provider.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced in dadd9f6. Removed the custom oidc.py entirely and switched to mozilla-django-oidc — a standard Django OIDC client library that handles the full authorization code flow (login redirect, callback, token exchange, userinfo) out of the box.

django-oauth-toolkit is an OIDC provider library (for building an auth server), so it can't act as an OIDC client for login.ubuntu.com. mozilla-django-oidc is the direct OIDC replacement for django_openid_auth — it's a client/RP library purpose-built for authenticating users via an external OIDC provider.

The only custom code is backends.py — a small OIDCAuthenticationBackend subclass that handles Launchpad team-to-group mapping (same logic as the original OPENID_LAUNCHPAD_TEAMS_MAPPING). All OIDC protocol handling is delegated to the library.

Copilot AI changed the title Convert errors from django_openid_auth to django-oauth-toolkit with login.ubuntu.com OIDC SSO Convert errors from django_openid_auth to mozilla-django-oidc with login.ubuntu.com OIDC SSO Mar 11, 2026
@Hyask
Copy link
Copy Markdown
Collaborator

Hyask commented Mar 11, 2026

@copilot
Change of plans again.
Let's use https://python-social-auth.readthedocs.io/en/latest/backends/launchpad.html instead.
This should mostly work out of the box.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 11, 2026

@copilot
Change of plans again.
Let's use https://python-social-auth.readthedocs.io/en/latest/backends/launchpad.html instead.
...

Switched to python-social-auth with the built-in LaunchpadOpenId backend in 395c345.

The integration is minimal — social-auth-app-django handles the full OpenID flow with login.launchpad.net out of the box. No custom backends or OIDC views needed. Changed files:

  • settings.py: LaunchpadOpenId backend, social_django app, LOGIN_URL/login/launchpad/
  • urls.py: social_django.urls at /login/
  • config.py: removed openid_trust_root
  • pyproject.toml: social-auth-app-django>=5.0.0

Launchpad team-to-group mapping is dropped per follow-up guidance.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • python-social-auth.readthedocs.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Convert errors from django_openid_auth to mozilla-django-oidc with login.ubuntu.com OIDC SSO Convert errors from django_openid_auth to python-social-auth with Launchpad backend Mar 11, 2026
…ckend

Replace the deprecated django_openid_auth with social-auth-app-django
using the built-in LaunchpadOpenId backend. This uses python-social-auth's
standard OpenID flow with login.launchpad.net.

- settings.py: OpenIDBackend → LaunchpadOpenId, social_django in
  INSTALLED_APPS, removed all OPENID_* settings and team mapping,
  LOGIN_URL → /login/launchpad/, error URL → /login-failed
- urls.py: mount social_django.urls at /login/
- config.py: remove openid_trust_root (not needed)
- pyproject.toml: add social-auth-app-django>=5.0.0

Co-authored-by: Hyask <7489759+Hyask@users.noreply.github.com>
@Hyask Hyask force-pushed the copilot/convert-errors-to-django-oauth-toolkit branch from 2971511 to e26e5bf Compare March 11, 2026 16:36
@Hyask Hyask force-pushed the copilot/convert-errors-to-django-oauth-toolkit branch from e26e5bf to 6147b9f Compare March 12, 2026 15:28
@Hyask Hyask marked this pull request as ready for review March 12, 2026 15:33
@Hyask Hyask merged commit 9ee090a into main Mar 12, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Convert errors to using django-oauth-toolkit

2 participants