wip
This commit is contained in:
parent
42a1681dbc
commit
a7910057a3
@ -1,5 +1,5 @@
|
|||||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||||
import { apps, metadata } from '../../../services';
|
import { metadata } from '../../../services';
|
||||||
import type { App, IdPMetadata } from '../../../types';
|
import type { App, IdPMetadata } from '../../../types';
|
||||||
|
|
||||||
export default async function handler(
|
export default async function handler(
|
||||||
@ -12,26 +12,26 @@ export default async function handler(
|
|||||||
|
|
||||||
async function create(req: NextApiRequest) {
|
async function create(req: NextApiRequest) {
|
||||||
const {
|
const {
|
||||||
sp_acs_url,
|
acs_url,
|
||||||
sp_entity_id,
|
entity_id,
|
||||||
name = 'My App',
|
name = 'My App',
|
||||||
description = null,
|
description = null,
|
||||||
} = req.body;
|
} = req.body;
|
||||||
|
|
||||||
const certificate = 'certificate';
|
const certificate = 'EwZHb29nbGUxGDAWBgNVBAsTD0dv';
|
||||||
|
|
||||||
const app = await apps.create({
|
return res
|
||||||
sp_acs_url,
|
.status(200)
|
||||||
sp_entity_id,
|
.json(metadata.create(acs_url, entity_id, certificate));
|
||||||
name,
|
|
||||||
description,
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,17 +2,16 @@ import axios from 'axios';
|
|||||||
import type { NextPage } from 'next';
|
import type { NextPage } from 'next';
|
||||||
import { ChangeEvent, FormEvent, useState } from 'react';
|
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 Apps: NextPage = () => {
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
sp_acs_url: null,
|
acs_url: null,
|
||||||
sp_entity_id: null,
|
entity_id: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [metadata, setMetadata] = useState({
|
||||||
|
sso_url: null,
|
||||||
|
entity_id: null,
|
||||||
|
certificate: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => {
|
const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
@ -25,9 +24,11 @@ const Apps: NextPage = () => {
|
|||||||
const createApp = async (e: FormEvent) => {
|
const createApp = async (e: FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const app = await axios.post('/api/apps', {
|
const {data} = await axios.post('/api/apps', {
|
||||||
...formData
|
...formData
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setMetadata(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -36,19 +37,25 @@ const Apps: NextPage = () => {
|
|||||||
<div className="mb-4">
|
<div className="mb-4">
|
||||||
<label className="block text-sm mb-2">
|
<label className="block text-sm mb-2">
|
||||||
ACS URL
|
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>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mb-4">
|
<div className="mb-4">
|
||||||
<label className="block text-sm mb-2">
|
<label className="block text-sm mb-2">
|
||||||
Entity ID
|
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>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="submit" className="bg-blue-500 text-white py-2 px-4 rounded">Build IdP Metadata</button>
|
<button type="submit" className="bg-blue-500 text-white py-2 px-4 rounded">Build IdP Metadata</button>
|
||||||
</form>
|
</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>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,16 +1,20 @@
|
|||||||
import * as xmlbuilder2 from 'xmlbuilder2';
|
|
||||||
import type { IdPMetadata } from '../types';
|
import type { IdPMetadata } from '../types';
|
||||||
|
|
||||||
|
const baseUrl = 'http://localhost:3000/saml';
|
||||||
|
|
||||||
export const create = (
|
export const create = (
|
||||||
acsUrl: string,
|
acs_url: string,
|
||||||
entityId: string,
|
entity_id: string,
|
||||||
certificate: string
|
certificate: string
|
||||||
): IdPMetadata => {
|
): IdPMetadata => {
|
||||||
const xml = xmlbuilder2.create();
|
const params = new URLSearchParams({
|
||||||
|
acs_url,
|
||||||
|
entity_id,
|
||||||
|
}).toString();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
sso_url: 'string',
|
sso_url: `${baseUrl}?${params}`,
|
||||||
entity_id: 'string',
|
entity_id: `${baseUrl}?${params}`,
|
||||||
certificate: 'string',
|
certificate: certificate,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
export type ServiceProvider = {
|
export type ServiceProvider = {
|
||||||
sp_acs_url: string;
|
acs_url: string;
|
||||||
sp_entity_id: string;
|
entity_id: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type IdentityProvider = {
|
export type IdentityProvider = {
|
||||||
@ -15,9 +15,7 @@ export type App = {
|
|||||||
certificate: string;
|
certificate: string;
|
||||||
} & ServiceProvider;
|
} & ServiceProvider;
|
||||||
|
|
||||||
// export type IdPMetadata = {
|
export type IdPMetadata = {
|
||||||
// sso_url: string;
|
certificate: string;
|
||||||
// entity_id: string;
|
fingerprint?: string;
|
||||||
// certificate: string;
|
} & IdentityProvider;
|
||||||
// fingerprint?: string;
|
|
||||||
// };
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user