From 7919ef8fcce0563e3975695fa9c4cb663af6e75a Mon Sep 17 00:00:00 2001 From: Kiran Date: Thu, 17 Feb 2022 14:51:19 +0530 Subject: [PATCH] Save the certificate to db --- README.md | 18 ++++-------------- pages/api/apps/index.ts | 6 +++++- pages/apps/index.tsx | 11 +++-------- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index b6e69db..3e16c16 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,7 @@ -# Backlog - -- Form validation -- Feed some users -- Fix the download metadata -- Add the SAML response -- Fix the SAML metadata URL -- Improve the UI - -https://github.com/prisma/prisma/issues/4571#issuecomment-747496127 +# Mock SAML from BoxyHQ http://localhost:4000/apps/saml?RelayState&SAMLRequest= -## Pages -- Create an app -- List all app -- View individual app page (with Download Metadata button and Delete button) \ No newline at end of file +- Parse the SAML Request +- Create the SAML Response +- Fix the certificate \ No newline at end of file diff --git a/pages/api/apps/index.ts b/pages/api/apps/index.ts index f02cb7f..be14ad5 100644 --- a/pages/api/apps/index.ts +++ b/pages/api/apps/index.ts @@ -1,6 +1,7 @@ import type { NextApiRequest, NextApiResponse } from 'next'; import type { App, IdPMetadata } from '../../../types'; import prisma from '../../../lib/prisma'; +import { createCertificate, createIdPMetadataXML } from '../../../utils'; export default async function handler( req: NextApiRequest, @@ -32,12 +33,15 @@ export default async function handler( description = null, } = req.body; + const certificate = await createCertificate(); + const app = await prisma.app.create({ data: { name, acs_url, entity_id, - description + description, + certificate, } }); diff --git a/pages/apps/index.tsx b/pages/apps/index.tsx index bb39f97..7d5f913 100644 --- a/pages/apps/index.tsx +++ b/pages/apps/index.tsx @@ -1,6 +1,7 @@ import axios from 'axios'; import type { NextPage } from 'next'; import { ChangeEvent, FormEvent, useState } from 'react'; +import Router from 'next/router'; const Apps: NextPage = () => { const [formData, setFormData] = useState({ @@ -9,12 +10,6 @@ const Apps: NextPage = () => { entity_id: null, }); - const [metadata, setMetadata] = useState({ - sso_url: null, - entity_id: null, - certificate: null, - }); - const handleInputChange = (e: ChangeEvent) => { setFormData({ ...formData, @@ -25,11 +20,11 @@ const Apps: NextPage = () => { const createApp = async (e: FormEvent) => { e.preventDefault(); - const {data} = await axios.post('/api/apps', { + const { data: app } = await axios.post('/api/apps', { ...formData }); - setMetadata(data); + await Router.push(`/apps/${app.id}`); }; return (