Files
claudeandClaude Opus 5.5 fc3120ee3f OpenID Connect login for Funkwhale as a plugin
Turns on django-allauth's generic openid_connect provider, which
Funkwhale already ships, and wires it to Funkwhale accounts: actor and
libraries on first login, admin by username or group, optional link by
e-mail. The front assets add a login button to the web app and proxy
/accounts/ to the API. Tested end to end against Funkwhale 2.0.13 and
Dex v2.44.0 (tests/compose.yaml).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 15:14:33 -05:00

55 lines
2.2 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
from django.apps import AppConfig
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from . import conf
class FunkwhaleOIDCConfig(AppConfig):
name = "funkwhale_oidc"
label = "funkwhale_oidc"
verbose_name = "OpenID Connect login"
def ready(self):
c = conf.get()
missing = [k for k in ("server_url", "client_id", "client_secret") if not c[k]]
if missing:
raise ImproperlyConfigured(
"funkwhale_oidc: set "
+ ", ".join(f"FUNKWHALE_OIDC_{k.upper()}" for k in missing)
)
# django-allauth reads its settings on every access, so setting them
# here (after Funkwhale's settings module ran) is enough.
settings.SOCIALACCOUNT_PROVIDERS = {
**getattr(settings, "SOCIALACCOUNT_PROVIDERS", {}),
"openid_connect": {
"OAUTH_PKCE_ENABLED": c["pkce"],
"APPS": [
{
"provider_id": c["provider_id"],
"name": c["name"],
"client_id": c["client_id"],
"secret": c["client_secret"],
"settings": {
"server_url": c["server_url"],
"scope": c["scopes"],
},
}
],
},
}
settings.SOCIALACCOUNT_ADAPTER = "funkwhale_oidc.adapters.SocialAccountAdapter"
settings.ACCOUNT_ADAPTER = "funkwhale_oidc.adapters.AccountAdapter"
# The SPA links straight to the provider; there is no allauth HTML
# page in Funkwhale to confirm a POST on.
# Callback URLs are built from the request; behind a TLS-terminating
# proxy that may look like plain http.
settings.ACCOUNT_DEFAULT_HTTP_PROTOCOL = getattr(settings, "FUNKWHALE_PROTOCOL", "https")
settings.SOCIALACCOUNT_LOGIN_ON_GET = True
settings.SOCIALACCOUNT_AUTO_SIGNUP = True
settings.SOCIALACCOUNT_STORE_TOKENS = False
settings.SOCIALACCOUNT_EMAIL_AUTHENTICATION = c["link_by_email"]
settings.SOCIALACCOUNT_EMAIL_AUTHENTICATION_AUTO_CONNECT = c["link_by_email"]