From eb73c90b2edb28cc84331186fb5b8983f88985da Mon Sep 17 00:00:00 2001 From: Jakob <9266151+chief-nerd@users.noreply.github.com> Date: Fri, 4 Jul 2025 08:36:28 +0200 Subject: [PATCH] fix(server): allow MS Office365 / Azure compatibility by making OIDC.preferred_username optional (#13027) > [!NOTE] > **This is a reopened (already approved) PR** > Needed to reopen https://github.com/toeverything/AFFiNE/pull/13011 because commit email was wrong and I could not sign the CLA Make Office365 / Azure login possible by making preferred_username optional. This is NOT send in the token of MS. To make this work you ALSO need to set the oidc.config.args.id to "email" (there preferred_username is used as default) Source: https://github.com/toeverything/AFFiNE/blob/canary/packages/backend/server/src/plugins/oauth/providers/oidc.ts#L152 ## Summary by CodeRabbit * **Bug Fixes** * Improved compatibility with OIDC providers by allowing the preferred username field to be optional during user info validation. --- packages/backend/server/src/plugins/oauth/providers/oidc.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/server/src/plugins/oauth/providers/oidc.ts b/packages/backend/server/src/plugins/oauth/providers/oidc.ts index 97509d02b..1da1be693 100644 --- a/packages/backend/server/src/plugins/oauth/providers/oidc.ts +++ b/packages/backend/server/src/plugins/oauth/providers/oidc.ts @@ -21,7 +21,7 @@ const OIDCTokenSchema = z.object({ const OIDCUserInfoSchema = z .object({ sub: z.string(), - preferred_username: z.string(), + preferred_username: z.string().optional(), email: z.string().email(), name: z.string(), groups: z.array(z.string()).optional(),