OIDC master
authorRadek Czajka <radekczajka@wolnelektury.pl>
Fri, 20 Nov 2026 22:17:35 +0000 (23:17 +0100)
committerRadek Czajka <radekczajka@wolnelektury.pl>
Fri, 20 Nov 2026 22:17:35 +0000 (23:17 +0100)
src/cas/settings.py
src/emails/oidc.py

index 5668804..7abd90a 100644 (file)
@@ -172,6 +172,12 @@ CAS_CUSTOM_ATTRIBUTES_CALLBACK = 'cas.utils.custom_attributes_callback'
 
 
 OIDC_USERINFO = 'emails.oidc.userinfo'
+# Include user claims in ID token, so clients don't need to call userinfo.
+OIDC_IDTOKEN_INCLUDE_CLAIMS = True
+# Fixed issuer base URL, e.g. https://cas.example.org
+# (the issuer will be ISSUER_URL + '/openid').
+# Without it, the issuer is derived from the request.
+ISSUER_URL = os.environ.get('ISSUER_URL') or None
 
 PASSWORD_HASHERS = (
     'cas.hashers.FNPBCryptPasswordHasher',
index e8c1196..f2377f0 100644 (file)
@@ -1,7 +1,26 @@
 from . import BASE_DOMAINS
 
 
+def user_email(user):
+    if BASE_DOMAINS:
+        return f"{user.username}@{BASE_DOMAINS[0]}"
+    return user.email
+
+
 def userinfo(claims, user):
-    return {
-        "email": f"{user.username}@{BASE_DOMAINS[0]}"
-    }
+    """
+    Claims for OIDC clients (see OIDC_USERINFO setting).
+
+    `preferred_username` is used e.g. by Matrix-Synapse as the localpart
+    and by Redmine (redmine_oauth) as the login.
+    """
+    email = user_email(user)
+    claims.update({
+        "preferred_username": user.username,
+        "name": user.get_full_name() or user.username,
+        "given_name": user.first_name,
+        "family_name": user.last_name,
+        "email": email,
+        "email_verified": bool(email),
+    })
+    return claims