wip
This commit is contained in:
parent
42a1681dbc
commit
a7910057a3
@ -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,25 +12,25 @@ 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);
|
||||
|
||||
return res.status(200).json(idPMetadata);
|
||||
// const app = await apps.create({
|
||||
// acs_url,
|
||||
// entity_id,
|
||||
// name,
|
||||
// description,
|
||||
// certificate,
|
||||
// });
|
||||
|
||||
// return res.status(200).json(app);
|
||||
}
|
||||
|
||||
@ -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<HTMLInputElement>) => {
|
||||
@ -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 = () => {
|
||||
<div className="mb-4">
|
||||
<label className="block text-sm mb-2">
|
||||
ACS URL
|
||||
<input type="text" name="sp_acs_url" onChange={handleInputChange} required className="border rounded w-full py-2 px-3" placeholder="ACS URL" />
|
||||
<input type="text" name="acs_url" onChange={handleInputChange} required className="border rounded w-full py-2 px-3" placeholder="ACS URL" />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="mb-4">
|
||||
<label className="block text-sm mb-2">
|
||||
Entity ID
|
||||
<input type="text" name="sp_entity_id" onChange={handleInputChange} required className="border rounded w-full py-2 px-3" placeholder="Entity ID" />
|
||||
<input type="text" name="entity_id" onChange={handleInputChange} required className="border rounded w-full py-2 px-3" placeholder="Entity ID" />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<button type="submit" className="bg-blue-500 text-white py-2 px-4 rounded">Build IdP Metadata</button>
|
||||
</form>
|
||||
|
||||
<ul className="bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4">
|
||||
<li className="px-2 py-2">SSO URL: {metadata.sso_url}</li>
|
||||
<li className="px-2 py-2">Entity ID: {metadata.entity_id}</li>
|
||||
<li className="px-2 py-2">Certificate: {metadata.certificate}</li>
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@ -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,
|
||||
};
|
||||
};
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user