From 7c03059bc06b706330e8f67707f21e370ad44f2f Mon Sep 17 00:00:00 2001
From: Armand Didierjean <95971503+armanddidierjean@users.noreply.github.com>
Date: Sun, 26 Nov 2023 05:13:42 +0100
Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20support=20for=20OpenID=20Conn?=
=?UTF-8?q?ect=20(#939)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../self-hosting/configuration-options.mdx | 46 ++++
apps/landing/declarations/environment.d.ts | 43 ++++
apps/web/declarations/environment.d.ts | 20 ++
apps/web/public/locales/en/app.json | 4 +-
apps/web/src/app/[locale]/(auth)/layout.tsx | 10 +-
.../app/[locale]/(auth)/login/login-form.tsx | 157 ++++++++++++
.../src/app/[locale]/(auth)/login/page.tsx | 30 ++-
.../src/app/[locale]/(auth)/register/page.tsx | 24 +-
.../(auth)/register/register-page.tsx | 31 +--
apps/web/src/components/auth/auth-forms.tsx | 146 +----------
apps/web/src/components/auth/auth-layout.tsx | 35 +--
apps/web/src/utils/auth.ts | 236 ++++++++++--------
apps/web/src/utils/constants.ts | 4 +
.../migration.sql | 20 ++
.../migration.sql | 2 +
.../migration.sql | 32 +++
packages/database/prisma/schema.prisma | 22 ++
turbo.json | 5 +
18 files changed, 562 insertions(+), 305 deletions(-)
create mode 100644 apps/web/src/app/[locale]/(auth)/login/login-form.tsx
create mode 100644 packages/database/prisma/migrations/20231117153753_add_nextauth_provider_accounts/migration.sql
create mode 100644 packages/database/prisma/migrations/20231118134458_add_account_user_index/migration.sql
create mode 100644 packages/database/prisma/migrations/20231122061137_map_account_table_names/migration.sql
diff --git a/apps/docs/self-hosting/configuration-options.mdx b/apps/docs/self-hosting/configuration-options.mdx
index d9cb524ab..350158fe9 100644
--- a/apps/docs/self-hosting/configuration-options.mdx
+++ b/apps/docs/self-hosting/configuration-options.mdx
@@ -68,3 +68,49 @@ These variables need to be configured to let Rallly send out transactional email
Enable TLS for your SMTP connection
+
+### Single Sign On (SSO) with OpenID Connect (OIDC)
+
+To enable SSO with an OIDC compliant identity provider you will need to configure the following variables.
+
+
+ Must be set to `true` to enable OIDC Login
+
+
+
+ The user-facing name of your provider as it will be shown on the login page
+
+
+
+ URL of the `.well-known/openid-configuration` endpoint for your OIDC provider
+
+
+
+ The client ID of your OIDC application
+
+
+
+ The client secret of your OIDC application
+
+
+#### Required Scopes
+
+The following scopes are required for OIDC to function properly.
+
+- `openid`: Essential for OIDC to function, used to perform authentication.
+- `profile`: Access to the user's personal information such as name and picture.
+- `email`: Access to the user's email address.
+
+#### Callback URL / Redirect URI
+
+The callback URL for your OIDC application must be set to:
+
+```
+{NEXT_PUBLIC_BASE_URL}/api/auth/callback/oidc
+```
+
+
+ Replace `{NEXT_PUBLIC_BASE_URL}` with the base URL of your Rallly instance.
+
+
+Ensure this URL is added to the list of allowed redirect URIs in your OIDC provider's application settings.
diff --git a/apps/landing/declarations/environment.d.ts b/apps/landing/declarations/environment.d.ts
index 2258f7b3b..19d1ec580 100644
--- a/apps/landing/declarations/environment.d.ts
+++ b/apps/landing/declarations/environment.d.ts
@@ -68,6 +68,49 @@ declare global {
* Determines what email provider to use. "smtp" or "ses"
*/
EMAIL_PROVIDER?: "smtp" | "ses";
+ /**
+ * Name of the oidc provider
+ */
+ OIDC_NAME?: string;
+ /**
+ * URL of the oidc provider .well-known/openid-configuration endpoint
+ */
+ OIDC_DISCOVERY_URL?: string;
+ /**
+ * Client ID of the oidc provider
+ */
+ OIDC_CLIENT_ID?: string;
+ /**
+ * Client secret of the oidc provider
+ */
+ OIDC_CLIENT_SECRET?: string;
+ /**
+ * Scopes that should be used when configuring the oidc provider
+ */
+ OIDC_SCOPES?: string;
+ /**
+ * If Rallly should expect the oidc provider to return an ID token
+ */
+ OIDC_ID_TOKEN_EXPECTED?: string;
+ /**
+ * When using an oidc provider that support the userinfo endpoint, set this to "true" to
+ * use it instead of getting the user info from the ID token
+ */
+ OIDC_FORCE_USER_INFO?: string;
+ /**
+ * When using a provider that does not provide a userinfo endpoint in its discovery document,
+ * `OIDC_FORCE_USER_INFO` may be set to the URL of the userinfo endpoint.
+ * `OIDC_USER_INFO_URL` may not be usable when `OIDC_FORCE_USER_INFO` is set to `true`
+ */
+ OIDC_USER_INFO_URL?: string;
+ /**
+ * The name of the `name` field returned by the oidc provider
+ */
+ OIDC_NAME_CLAIM?: string;
+ /**
+ * The name of the `email` field returned by the oidc provider
+ */
+ OIDC_EMAIL_CLAIM?: string;
/**
* AWS access key ID
*/
diff --git a/apps/web/declarations/environment.d.ts b/apps/web/declarations/environment.d.ts
index a91ab98d9..ed96abbe1 100644
--- a/apps/web/declarations/environment.d.ts
+++ b/apps/web/declarations/environment.d.ts
@@ -64,6 +64,26 @@ declare global {
* Determines what email provider to use. "smtp" or "ses"
*/
EMAIL_PROVIDER?: "smtp" | "ses";
+ /**
+ * Set to "true" to enable OIDC authentication
+ */
+ OIDC_ENABLED?: string;
+ /**
+ * Name of the oidc provider
+ */
+ OIDC_NAME?: string;
+ /**
+ * URL of the oidc provider .well-known/openid-configuration endpoint
+ */
+ OIDC_DISCOVERY_URL?: string;
+ /**
+ * Client ID of the oidc provider
+ */
+ OIDC_CLIENT_ID?: string;
+ /**
+ * Client secret of the oidc provider
+ */
+ OIDC_CLIENT_SECRET?: string;
/**
* AWS access key ID
*/
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index f9153ac6f..d673ed56a 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -40,6 +40,7 @@
"location": "Location",
"locationPlaceholder": "Joe's Coffee Shop",
"login": "Login",
+ "loginWith": "Login with {provider}",
"logout": "Logout",
"manage": "Manage",
"mixedOptionsDescription": "You can't have both time and date options in the same poll. Which would you like to keep?",
@@ -226,5 +227,6 @@
"continueAs": "Continue as",
"finalizeFeature": "Finalize",
"duplicateFeature": "Duplicate",
- "pageMovedDescription": "Redirecting to {newUrl}"
+ "pageMovedDescription": "Redirecting to {newUrl}",
+ "notRegistered": "Don't have an account? Register"
}
diff --git a/apps/web/src/app/[locale]/(auth)/layout.tsx b/apps/web/src/app/[locale]/(auth)/layout.tsx
index 88418aa86..9469b2c6e 100644
--- a/apps/web/src/app/[locale]/(auth)/layout.tsx
+++ b/apps/web/src/app/[locale]/(auth)/layout.tsx
@@ -1,7 +1,7 @@
-"use client";
-
-import { AuthLayout } from "@/components/auth/auth-layout";
-
export default function Layout({ children }: { children: React.ReactNode }) {
- return {children};
+ return (
+