feat: add generic OIDC authentication (Okta, Auth0, Keycloak, OneLogin, ...)#683
Open
d-axel-b wants to merge 1 commit intogetnao:mainfrom
Open
feat: add generic OIDC authentication (Okta, Auth0, Keycloak, OneLogin, ...)#683d-axel-b wants to merge 1 commit intogetnao:mainfrom
d-axel-b wants to merge 1 commit intogetnao:mainfrom
Conversation
Add SSO login via any OIDC-compliant identity provider using
better-auth's genericOAuth plugin with OIDC discovery.
Backend:
- Register genericOAuth plugin in auth.ts when OIDC env vars are set
- Add 8 env vars: OIDC_PROVIDER_ID, OIDC_PROVIDER_NAME,
OIDC_DISCOVERY_URL, OIDC_CLIENT_ID, OIDC_CLIENT_SECRET,
OIDC_SCOPES, OIDC_AUTH_DOMAINS, OIDC_PKCE
- Enforce email domain allowlist in databaseHooks.user.create.before
- Include OIDC provider in isSocial check for user auto-provisioning
- Add tRPC authConfig.oidc.getConfig returning providerId + providerName
Frontend:
- Add genericOAuthClient plugin to auth client
- Add handleOidcSignIn using authClient.signIn.oauth2
- Render dynamic "Continue with {providerName}" button with LockKeyholeIcon
Docs:
- Add apps/backend/docs/auth-oidc.md with setup walkthroughs for
Okta, Auth0, Keycloak, and OneLogin
- Update .env.example with OIDC configuration block
Tests:
- 10 domain allowlist tests (auth-hooks-oidc.test.ts)
- 5 tRPC getConfig endpoint tests (auth-config-oidc.test.ts)
Contributor
|
This PR was auto-closed. Only contributors approved with Maintainers review auto-closed issues daily. Issues that do not meet the quality bar in CONTRIBUTING.md will not be reopened or receive a reply. If a maintainer replies See CONTRIBUTING.md. |
Contributor
🚀 Preview Deployment
Preview will be automatically removed when this PR is closed. |
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds SSO login via any OIDC-compliant identity provider using better-auth's
genericOAuthplugin. One integration that works with Okta, Auth0, Keycloak, OneLogin, and any provider that exposes a standard OIDC discovery document.Configuration
Set the following environment variables to enable:
OIDC_DISCOVERY_URL(required) — provider's.well-known/openid-configurationURLOIDC_CLIENT_ID(required)OIDC_CLIENT_SECRET(required)OIDC_PROVIDER_ID— defaults tooidc, used in callback URL and button logicOIDC_PROVIDER_NAME— defaults toSSO, shown on the login buttonOIDC_SCOPES— defaults toopenid,profile,emailOIDC_AUTH_DOMAINS— optional comma-separated email domain allowlistOIDC_PKCE— defaults totrueWhen unset, the SSO button is hidden.
Redirect URI to register in your IdP:
https://<your-nao-host>/api/auth/oauth2/callback/{OIDC_PROVIDER_ID}What's included
genericOAuthplugin registration, env schema (8 vars), domain allowlist enforcement indatabaseHooks.user.create.before, OIDC users included inisSocialcheck for auto-provisioning, tRPCauthConfig.oidc.getConfigendpointgenericOAuthClientplugin, dynamichandleOidcSignInviasignIn.oauth2, conditional "Continue with {providerName}" button withLockKeyholeIconapps/backend/docs/auth-oidc.mdwith walkthroughs for Okta, Auth0, Keycloak, and OneLoginTest plan
npm run lintpasses (no new errors — pre-existing drizzle-orm type issues unrelated)npm testpasses (15/15 new tests pass)Manual smoke against an OIDC provider:
/Some manual test remains