Enterprise SSO Component
The Enterprise SSO Component can be used to assist in collecting the necessary information from your users to setup Enterprise SSO.
Installation
Section titled “Installation”-
Install shadcn in your application.
-
Install the component.
Terminal window npx shadcn@latest add https://components.propelauth.com/r/enterprise-sso.json
Properties
Section titled “Properties”redirectUrl string
Section titled “redirectUrl string”Also known as a callback URL, this is the value that your customers will be redirected to after authenticating with their IdP. This value must match the value used when Creating the OIDC Client.
api SsoApi
Section titled “api SsoApi”Includes three methods to be used to fetch, create, and delete OIDC clients in your backend. See below for an example.
-
get
Section titled “get () => Promise<Result<{ idpInfoFromCustomer?: IdpInfoFromCustomer }>>;”() => Promise<Result<{ idpInfoFromCustomer?: IdpInfoFromCustomer }>>;A fetch request to your backend that returns the
idpInfoFromCustomerobject from the Fetch OIDC Client API. -
upsert
Section titled “upsert (params: { idpInfoFromCustomer: IdpInfoFromCustomer }) => Promise<Result<void>>”(params: { idpInfoFromCustomer: IdpInfoFromCustomer }) => Promise<Result<void>>A POST request to your backend to create an OIDC client.
-
remove
Section titled “remove () => Promise<Result<void>>”() => Promise<Result<void>>A DELETE request to your backend to delete an OIDC client.
Frontend Example
Section titled “Frontend Example”import SsoSetup from '@/components/sso/sso-setup';import type { SsoApi } from '@/lib/sso/sso-types';
const api: SsoApi = { async get() { const r = await fetch(`/api/setup/sso`); if (!r.ok) return { ok: false, error: { status: r.status, message: await r.text() } }; return { ok: true, data: await r.json() }; }, async upsert(body) { const r = await fetch(`/api/setup/sso`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body), }); return r.ok ? { ok: true, data: undefined } : { ok: false, error: { status: r.status, message: await r.text() } }; }, async remove() { const r = await fetch(`/api/setup/sso`, { method: "DELETE" }, ); return r.ok ? { ok: true, data: undefined } : { ok: false, error: { status: r.status, message: await r.text() } }; },};
export default function Page() { return ( <SsoSetup redirectUrl='http://<your-domain>/api/auth/finish-login' api={api} /> );}Backend Example
Section titled “Backend Example”It is required to build three routes in your backend to use the SsoSetup component - each corresponding with one of the three methods included in the api argument detailed above.
Returns the idpInfoFromCustomer object from the Fetch OIDC Client API.
router.get("/api/setup/sso", async (_req: Request, res: Response) => { const result = await client.sso.management.fetchOidcClient({ customerId: "{your_id_for_your_customer}", }); if (result.ok) { const response = {"idpInfoFromCustomer": result.idpInfoFromCustomer}; res.json(response); } else { res.status(404).json({ error: result.error }); }});Creates an OIDC client using the idpInfoFromCustomer object sent from the frontend component.
router.post("/api/setup/sso", async (req: Request, res: Response) => { const createResult = await client.sso.management.createOidcClient({ idpInfoFromCustomer: req.body.idpInfoFromCustomer, customerId: "{your_id_for_your_customer}", redirectUrl: "http://<your-domain>/api/auth/finish-login" });
if (result.ok) { res.json({ success: true }); } else { res.status(400).json({ error: result.error }); }});DELETE
Section titled “DELETE”router.delete("/api/setup/sso", async (_req: Request, res: Response) => { const deleteResult = await client.sso.management.deleteOidcClient({ customerId: "{your_id_for_your_customer}", });
if (deleteResult.ok) { res.json({ message: "SSO configuration deleted successfully" }); } else { res.status(404).json({ error: result.error }); }});