-
-
Notifications
You must be signed in to change notification settings - Fork 172
feat: add Kanidm OIDC support with PKCE and ID token algo config #682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { PrismaAdapter } from '@next-auth/prisma-adapter'; | ||
| import { Prisma } from '@prisma/client'; | ||
| import { type GetServerSidePropsContext } from 'next'; | ||
| import { type DefaultSession, type NextAuthOptions, type User, getServerSession } from 'next-auth'; | ||
| import { type Adapter, type AdapterAccount, type AdapterUser } from 'next-auth/adapters'; | ||
|
|
@@ -71,32 +72,21 @@ const SplitProPrismaAdapter = (...args: Parameters<typeof PrismaAdapter>): Adapt | |
| return prismaCreateUser(user); | ||
| }, | ||
| linkAccount: async (account: AdapterAccount) => { | ||
| // oxlint-disable-next-line typescript/no-unsafe-assignment | ||
| const originalLinkAccount = prismaAdapter.linkAccount; | ||
|
|
||
| if (!originalLinkAccount) { | ||
| throw new Error('Adapter is missing the linkAccount method.'); | ||
| } | ||
|
|
||
| // Keycloak and Gitlab provide some non-standard fields that do not exist in the prisma schema. | ||
| // OIDC providers can provide non-standard fields that do not exist in the prisma schema. | ||
| // We strip them out before passing them on to the original adapter. | ||
| if (account.provider === 'keycloak') { | ||
| const { | ||
| 'not-before-policy': _notBeforePolicy, | ||
| refresh_expires_in: _refresh_expires_in, | ||
| ...standardAccountData | ||
| } = account as AdapterAccount & Record<string, unknown>; | ||
| const knownAccountFields = new Set<string>(Object.values(Prisma.AccountScalarFieldEnum)); | ||
|
|
||
| return originalLinkAccount(standardAccountData as AdapterAccount); | ||
| } else if (account.provider === 'gitlab') { | ||
| const { created_at: _createdAt, ...standardAccountData } = account as AdapterAccount & | ||
| Record<string, unknown>; | ||
|
|
||
| return originalLinkAccount(standardAccountData as AdapterAccount); | ||
| } | ||
| const sanitised = Object.fromEntries( | ||
| Object.entries(account as Record<string, unknown>).filter(([k]) => | ||
| knownAccountFields.has(k), | ||
| ), | ||
| ) as AdapterAccount; | ||
|
|
||
| // Default: proceed directly | ||
| return originalLinkAccount(account); | ||
| return originalLinkAccount(sanitised); | ||
| }, | ||
| } as Adapter; | ||
| }; | ||
|
|
@@ -253,6 +243,10 @@ function getProviders() { | |
| type: 'oauth', | ||
| wellKnown: env.OIDC_WELL_KNOWN_URL, | ||
| authorization: { params: { scope: 'openid email profile' } }, | ||
| checks: env.OIDC_PKCE_ENABLED ? ['pkce'] : [], | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as I understand OIDC, the encryption configs should be provided from the I am not familiar with Kandim, but please double check it's not an issue on their end or with your configuration, as setting these options by hand should not be required.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the feedback. I'm no OIDC expert myself. Here's what I could find out: Kanidm correctly advertises ES256 and its PKCE requirements in the .well-known files. These are the defaults Kanidm ships with. Disabling them is possible but the commands are along the lines of "enable legacy crypto" etc., highly suggesting that users should only mess with this if necessary. wget -qO- https://kanidm:8443/oauth2/openid/splitpro/.well-known/openid-configuration 2>/dev/null
"id_token_signing_alg_values_supported":["ES256"],
"code_challenge_methods_supported":["S256"]The issue appears to lie in
As far as I can tell adding in the
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I like this approach, thanks for digging into this! |
||
| client: env.OIDC_ID_TOKEN_SIGNED_RESPONSE_ALG | ||
| ? { id_token_signed_response_alg: env.OIDC_ID_TOKEN_SIGNED_RESPONSE_ALG } | ||
| : undefined, | ||
| allowDangerousEmailAccountLinking: env.OIDC_ALLOW_DANGEROUS_EMAIL_LINKING, | ||
| idToken: true, | ||
| profile(profile) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.