The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
started adding SCIM
Steven Tey5edf48c69036
diff --git a/lib/jackson.ts b/lib/jackson.tsindex a6ecd84494..cc2d45244f 100644--- a/lib/jackson.ts+++ b/lib/jackson.ts@@ -37,13 +37,15 @@ export default async function init() {!globalThis.connectionController ||!globalThis.apiController ||!globalThis.oauthController ||- !globalThis.samlSPConfig+ !globalThis.samlSPConfig ||+ !globalThis.directorySync) {const ret = await jackson(opts);globalThis.connectionController = ret.connectionAPIController;globalThis.apiController = ret.connectionAPIController;globalThis.oauthController = ret.oauthController;globalThis.samlSPConfig = ret.spConfig;+ globalThis.directorySync = ret.directorySyncController;}return {@@ -51,5 +53,6 @@ export default async function init() {apiController: globalThis.apiController,oauthController: globalThis.oauthController,samlSPConfig: globalThis.samlSPConfig,+ directorySync: global.directorySyncController,};}diff --git a/pages/api/auth/[...nextauth].tsx b/pages/api/auth/[...nextauth].tsxindex a123c0ba10..f2a25dc58a 100644--- a/pages/api/auth/[...nextauth].tsx+++ b/pages/api/auth/[...nextauth].tsx@@ -167,10 +167,7 @@ export const authOptions: NextAuthOptions = {},});}- } else if (- account?.provider === "saml" ||- account?.provider === "saml-idp"- ) {+ } else if (account?.provider === "saml") {const samlProfile = profile as Profile & {requested?: { tenant?: string };};@@ -198,6 +195,8 @@ export const authOptions: NextAuthOptions = {},});}+ } else if (account?.provider === "saml-idp") {+ console.log({ user, account, profile });}return true;},diff --git a/pages/api/projects/[slug]/scim.ts b/pages/api/projects/[slug]/scim.tsnew file mode 100644index 0000000000..e69de29bb2diff --git a/pages/api/scim/[...directory].ts b/pages/api/scim/[...directory].tsnew file mode 100644index 0000000000..73e0082f3f--- /dev/null+++ b/pages/api/scim/[...directory].ts@@ -0,0 +1,110 @@+import type { NextApiRequest, NextApiResponse } from "next";+import jackson from "#/lib/jackson";+import prisma from "#/lib/prisma";+import type {+ DirectorySyncEvent,+ DirectorySyncRequest,+} from "@boxyhq/saml-jackson";++// Fetch the auth token from the request headers+export const extractAuthToken = (req: NextApiRequest): string | null => {+ const authHeader = req.headers.authorization || null;++ return authHeader ? authHeader.split(" ")[1] : null;+};++export default async function handler(+ req: NextApiRequest,+ res: NextApiResponse,+) {+ const { directorySync } = await jackson();++ const { method, query, body } = req;++ const directory = query.directory as string[];+ const [directoryId, path, resourceId] = directory;++ // Handle the SCIM API requests+ const request: DirectorySyncRequest = {+ method: method as string,+ body: body ? JSON.parse(body) : undefined,+ directoryId,+ resourceId,+ resourceType: path === "Users" ? "users" : "groups",+ apiSecret: extractAuthToken(req),+ query: {+ count: req.query.count ? parseInt(req.query.count as string) : undefined,+ startIndex: req.query.startIndex+ ? parseInt(req.query.startIndex as string)+ : undefined,+ filter: req.query.filter as string,+ },+ };++ const { status, data } = await directorySync.requests.handle(+ request,+ handleEvents,+ );++ res.status(status).json(data);+}++// Handle the SCIM events+const handleEvents = async (event: DirectorySyncEvent) => {+ const { event: action, tenant: projectId, data } = event;+ console.log({ action, projectId, data });++ // User has been created+ if (action === "user.created" && "email" in data) {+ // const user = await prisma.user.upsert({+ // where: {+ // email: data.email,+ // },+ // update: {+ // name: `${data.first_name} ${data.last_name}`,+ // },+ // create: {+ // name: `${data.first_name} ${data.last_name}`,+ // email: data.email,+ // },+ // });+ // add to team+ }++ // User has been updated+ if (action === "user.updated" && "email" in data) {+ if (data.active === true) {+ const user = await prisma.user.upsert({+ where: {+ email: data.email,+ },+ update: {+ name: `${data.first_name} ${data.last_name}`,+ },+ create: {+ name: `${data.first_name} ${data.last_name}`,+ email: data.email,+ },+ });++ // add to team++ return;+ }++ // const user = await getUser({ email: data.email });++ // if (!user) {+ // return;+ // }++ // if (data.active === false) {+ // await deleteUser({ id: user.id });+ // }+ }++ // User has been removed+ if (action === "user.deleted" && "email" in data) {+ // await deleteUser({ email: data.email });+ }+};