Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

allow dangerous email linking

Steven Tey1fb454284310
diff --git a/app/app/(auth)/auth/saml/form.tsx b/app/app/(auth)/auth/saml/form.tsx
index 40c7b40f6a..fb36194796 100644
--- a/app/app/(auth)/auth/saml/form.tsx
+++ b/app/app/(auth)/auth/saml/form.tsx
@@ -11,7 +11,7 @@ export default function SAMLForm() {
useEffect(() => {
const code = searchParams?.get("code");
- signIn("idp-saml", {
+ signIn("saml-idp", {
callbackUrl: "/",
code,
});
diff --git a/app/app/(auth)/login/form.tsx b/app/app/(auth)/login/form.tsx
index 5d92a56a28..b01eb586dc 100644
--- a/app/app/(auth)/login/form.tsx
+++ b/app/app/(auth)/login/form.tsx
@@ -117,7 +117,7 @@ export default function LoginForm() {
onSubmit={async (e) => {
e.preventDefault();
setClickedSSO(true);
- fetch("/api/auth/sso/verify", {
+ fetch("/api/auth/saml/verify", {
method: "POST",
body: JSON.stringify({ slug: e.currentTarget.slug.value }),
}).then(async (res) => {
@@ -127,7 +127,7 @@ export default function LoginForm() {
setClickedSSO(false);
return;
}
- await signIn("boxyhq-saml", undefined, {
+ await signIn("saml", undefined, {
tenant: data.projectId,
product: "Dub",
});
diff --git a/lib/jackson.ts b/lib/jackson.ts
index 5c025717d6..a6ecd84494 100644
--- a/lib/jackson.ts
+++ b/lib/jackson.ts
@@ -6,7 +6,7 @@ import type {
ISPSAMLConfig,
} from "@boxyhq/saml-jackson";
-const samlPath = "/api/oauth/saml";
+const samlPath = "/api/auth/saml/callback";
const samlAudience = "https://saml.dub.sh";
const opts: JacksonOption = {
diff --git a/pages/api/auth/[...nextauth].tsx b/pages/api/auth/[...nextauth].tsx
index ba916c4a3d..b3a4a7ed7a 100644
--- a/pages/api/auth/[...nextauth].tsx
+++ b/pages/api/auth/[...nextauth].tsx
@@ -1,6 +1,5 @@
import EmailProvider from "next-auth/providers/email";
import GoogleProvider from "next-auth/providers/google";
-import BoxyHQSAMLProvider from "next-auth/providers/boxyhq-saml";
import CredentialsProvider from "next-auth/providers/credentials";
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import { sendEmail } from "emails";
@@ -34,18 +33,41 @@ export const authOptions: NextAuthOptions = {
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
allowDangerousEmailAccountLinking: true,
}),
- BoxyHQSAMLProvider({
- authorization: { params: { scope: "" } },
- issuer: process.env.NEXTAUTH_URL,
- clientId: "dummy",
- clientSecret: process.env.NEXTAUTH_SECRET as string,
- allowDangerousEmailAccountLinking: true,
- httpOptions: {
- timeout: 30000,
+ {
+ id: "saml",
+ name: "BoxyHQ",
+ type: "oauth",
+ version: "2.0",
+ checks: ["pkce", "state"],
+ authorization: {
+ url: `${process.env.NEXTAUTH_URL}/api/auth/saml/authorize`,
+ params: {
+ scope: "",
+ response_type: "code",
+ provider: "saml",
+ },
},
- }),
+ token: {
+ url: `${process.env.NEXTAUTH_URL}/api/auth/saml/token`,
+ params: { grant_type: "authorization_code" },
+ },
+ userinfo: `${process.env.NEXTAUTH_URL}/api/auth/saml/userinfo`,
+ profile: (profile) => {
+ return {
+ id: profile.id || "",
+ email: profile.email || "",
+ name: `${profile.firstName || ""} ${profile.lastName || ""}`.trim(),
+ email_verified: true,
+ };
+ },
+ options: {
+ clientId: "dummy",
+ clientSecret: process.env.NEXTAUTH_SECRET as string,
+ },
+ allowDangerousEmailAccountLinking: true,
+ },
CredentialsProvider({
- id: "idp-saml",
+ id: "saml-idp",
name: "IdP Login",
credentials: {
code: {},
@@ -83,13 +105,23 @@ export const authOptions: NextAuthOptions = {
return null;
}
- const { id, firstName, lastName, email } = userInfo;
+ const actualUser = await prisma.user.findUnique({
+ where: { email: userInfo.email },
+ });
+
+ // user is authorized but doesn't have a Dub account, prompt them to create one
+ if (!actualUser) {
+ return null;
+ }
+
+ const { id, name, email, image } = actualUser;
return {
id,
email,
- name: `${firstName} ${lastName}`.trim(),
+ name,
email_verified: true,
+ image,
};
},
}),
diff --git a/pages/api/oauth/authorize.ts b/pages/api/auth/saml/authorize.ts
similarity index 100%
rename from pages/api/oauth/authorize.ts
rename to pages/api/auth/saml/authorize.ts
diff --git a/pages/api/oauth/saml.ts b/pages/api/auth/saml/callback.ts
similarity index 100%
rename from pages/api/oauth/saml.ts
rename to pages/api/auth/saml/callback.ts
diff --git a/pages/api/oauth/token.ts b/pages/api/auth/saml/token.ts
similarity index 100%
rename from pages/api/oauth/token.ts
rename to pages/api/auth/saml/token.ts
diff --git a/pages/api/oauth/userinfo.ts b/pages/api/auth/saml/userinfo.ts
similarity index 100%
rename from pages/api/oauth/userinfo.ts
rename to pages/api/auth/saml/userinfo.ts
diff --git a/pages/api/auth/sso/verify.tsx b/pages/api/auth/saml/verify.tsx
similarity index 100%
rename from pages/api/auth/sso/verify.tsx
rename to pages/api/auth/saml/verify.tsx
diff --git a/pages/api/auth/sso/acs.ts b/pages/api/auth/sso/acs.ts
deleted file mode 100644
index cff4e64d6a..0000000000
--- a/pages/api/auth/sso/acs.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import type { NextApiRequest, NextApiResponse } from "next";
-
-import jackson from "#/lib/jackson";
-
-export default async function handler(
- req: NextApiRequest,
- res: NextApiResponse,
-) {
- const { oauthController } = await jackson();
-
- const { RelayState, SAMLResponse } = req.body;
-
- const { redirect_url } = await oauthController.samlResponse({
- RelayState,
- SAMLResponse,
- });
-
- return res.redirect(302, redirect_url as string);
-}
diff --git a/pages/api/projects/[slug]/saml.ts b/pages/api/projects/[slug]/saml.ts
index 46fca80f98..4b4e8a5366 100644
--- a/pages/api/projects/[slug]/saml.ts
+++ b/pages/api/projects/[slug]/saml.ts
@@ -14,7 +14,7 @@ export default withProjectAuth(async (req, res, project) => {
const response = {
connections,
issuer: "https://saml.dub.sh",
- acs: `${process.env.NEXTAUTH_URL}/api/oauth/saml`,
+ acs: `${process.env.NEXTAUTH_URL}/api/auth/saml/callback`,
};
return res.status(200).json(response);