diff --git a/pages/api/apps/index.ts b/pages/api/apps/index.ts index e799988..d838017 100644 --- a/pages/api/apps/index.ts +++ b/pages/api/apps/index.ts @@ -1,5 +1,5 @@ import type { NextApiRequest, NextApiResponse } from 'next'; -import { apps, metadata } from '../../../services'; +import { metadata } from '../../../services'; import type { App, IdPMetadata } from '../../../types'; export default async function handler( @@ -12,26 +12,26 @@ export default async function handler( async function create(req: NextApiRequest) { const { - sp_acs_url, - sp_entity_id, + acs_url, + entity_id, name = 'My App', description = null, } = req.body; - const certificate = 'certificate'; + const certificate = 'EwZHb29nbGUxGDAWBgNVBAsTD0dv'; - const app = await apps.create({ - sp_acs_url, - sp_entity_id, - name, - description, - certificate, - }); + return res + .status(200) + .json(metadata.create(acs_url, entity_id, certificate)); - const idPMetadata = metadata.create(sp_acs_url, sp_entity_id, certificate); + // const app = await apps.create({ + // acs_url, + // entity_id, + // name, + // description, + // certificate, + // }); - return res.status(200).json(idPMetadata); - - //return res.status(200).json(app); + // return res.status(200).json(app); } } diff --git a/pages/apps/index.tsx b/pages/apps/index.tsx index 471d60e..46ac3dd 100644 --- a/pages/apps/index.tsx +++ b/pages/apps/index.tsx @@ -2,17 +2,16 @@ import axios from 'axios'; import type { NextPage } from 'next'; import { ChangeEvent, FormEvent, useState } from 'react'; -// const a = new URLSearchParams({ -// sp_acs_url: 'http://localhost:3000/apps', -// sp_entity_id: 'https://saml.boxyhq.com', -// }).toString(); - -// console.log(a); - const Apps: NextPage = () => { const [formData, setFormData] = useState({ - sp_acs_url: null, - sp_entity_id: null, + acs_url: null, + entity_id: null, + }); + + const [metadata, setMetadata] = useState({ + sso_url: null, + entity_id: null, + certificate: null, }); const handleInputChange = (e: ChangeEvent) => { @@ -25,9 +24,11 @@ const Apps: NextPage = () => { const createApp = async (e: FormEvent) => { e.preventDefault(); - const app = await axios.post('/api/apps', { + const {data} = await axios.post('/api/apps', { ...formData }); + + setMetadata(data); }; return ( @@ -36,19 +37,25 @@ const Apps: NextPage = () => {
+ + ); }; diff --git a/services/metadata.ts b/services/metadata.ts index 06423c0..6975b34 100644 --- a/services/metadata.ts +++ b/services/metadata.ts @@ -1,16 +1,20 @@ -import * as xmlbuilder2 from 'xmlbuilder2'; import type { IdPMetadata } from '../types'; +const baseUrl = 'http://localhost:3000/saml'; + export const create = ( - acsUrl: string, - entityId: string, + acs_url: string, + entity_id: string, certificate: string ): IdPMetadata => { - const xml = xmlbuilder2.create(); + const params = new URLSearchParams({ + acs_url, + entity_id, + }).toString(); return { - sso_url: 'string', - entity_id: 'string', - certificate: 'string', + sso_url: `${baseUrl}?${params}`, + entity_id: `${baseUrl}?${params}`, + certificate: certificate, }; }; diff --git a/types/index.ts b/types/index.ts index 1a604ce..4e7ef57 100644 --- a/types/index.ts +++ b/types/index.ts @@ -1,6 +1,6 @@ export type ServiceProvider = { - sp_acs_url: string; - sp_entity_id: string; + acs_url: string; + entity_id: string; }; export type IdentityProvider = { @@ -15,9 +15,7 @@ export type App = { certificate: string; } & ServiceProvider; -// export type IdPMetadata = { -// sso_url: string; -// entity_id: string; -// certificate: string; -// fingerprint?: string; -// }; +export type IdPMetadata = { + certificate: string; + fingerprint?: string; +} & IdentityProvider;