mocksaml/pages/index.tsx

119 lines
4.4 KiB
TypeScript
Raw Permalink Normal View History

import { GetServerSideProps } from 'next';
2022-02-24 03:28:53 +00:00
import Link from 'next/link';
import React from 'react';
import config from '../lib/env';
import { IdPMetadata } from '../types';
2024-01-21 01:01:09 +00:00
import { getEntityId, getSSOUrl } from 'lib/entity-id';
2022-02-18 04:07:27 +00:00
const Home: React.FC<{ metadata: IdPMetadata; params: any }> = ({ metadata, params }) => {
const namespace = params.namespace;
2024-01-21 01:01:09 +00:00
const { ssoUrl: appUrl, entityId, certificate } = metadata;
const namespaceEntityId = getEntityId(entityId, namespace);
const metadataDownloadUrl =
'/api' + (namespace ? `/namespace/${namespace}` : '') + '/saml/metadata?download=true';
const metadataUrl = '/api' + (namespace ? `/namespace/${namespace}` : '') + '/saml/metadata';
2024-01-21 01:01:09 +00:00
const loginUrl = (namespace ? `/namespace/${namespace}` : '') + '/saml/login';
const ssoUrl = getSSOUrl(appUrl, namespace);
2022-01-08 15:11:13 +00:00
return (
<div className='flex min-h-screen justify-center bg-white pt-12'>
<div className='w-full max-w-4xl px-2 space-y-6'>
<h1 className='text-center text-xl font-semibold text-gray-900 md:text-2xl'>
2022-07-26 21:28:46 +00:00
A free SAML 2.0 Identity Provider for testing SAML SSO integrations.
</h1>
{/* Actions */}
<div className='flex flex-col gap-4 md:flex-row md:items-center md:justify-between'>
<div className='flex flex-col gap-3 md:flex-row'>
<Link
href={metadataDownloadUrl}
className='inline-flex items-center justify-center rounded-md
bg-primary px-4 py-2 text-sm font-semibold text-white
hover:bg-primary-hover
focus:outline-none focus:ring-2 focus:ring-primary-ring'>
Download Metadata
</Link>
<Link
href={metadataUrl}
target='_blank'
className='inline-flex items-center justify-center rounded-md
border border-primary px-4 py-2 text-sm font-semibold
text-primary hover:bg-primary-soft
focus:outline-none focus:ring-2 focus:ring-primary-ring'>
Metadata URL
</Link>
</div>
<Link
href={loginUrl}
className='inline-flex items-center justify-center rounded-md
border border-primary px-4 py-2 text-sm font-semibold
text-primary hover:bg-primary-soft
focus:outline-none focus:ring-2 focus:ring-primary-ring'>
Test IdP Login
2022-07-27 07:52:38 +00:00
</Link>
</div>
{/* Metadata Card */}
<div className='rounded-lg border border-gray-200 bg-white p-4 shadow-sm'>
<h2 className='mb-5 text-center text-2xl font-semibold text-gray-900'>Mock SAML Metadata</h2>
<div className='grid grid-cols-1 gap-5 md:grid-cols-2'>
<div>
<label className='block mb-1 text-sm font-medium text-gray-700'>SSO URL</label>
<input
type='text'
defaultValue={ssoUrl}
disabled
className='w-full rounded-md border border-gray-300 bg-gray-100 px-3 py-2 text-sm text-gray-700'
/>
2022-07-26 21:28:46 +00:00
</div>
<div>
<label className='block mb-1 text-sm font-medium text-gray-700'>Entity ID</label>
<input
type='text'
defaultValue={namespaceEntityId}
disabled
className='w-full rounded-md border border-gray-300 bg-gray-100 px-3 py-2 text-sm text-gray-700'
/>
2022-07-26 21:28:46 +00:00
</div>
<div className='md:col-span-2'>
<label className='block mb-1 text-sm font-medium text-gray-700'>Certificate</label>
2022-07-27 07:52:38 +00:00
<textarea
defaultValue={certificate}
disabled
className='h-48 w-full rounded-md border border-gray-300 bg-gray-100 px-3 py-2 text-sm font-mono text-gray-700'
/>
2022-07-27 07:52:38 +00:00
</div>
</div>
</div>
{/* Warning */}
<div className='rounded-md border border-red-200 bg-red-50 p-4'>
<p className='text-sm font-medium text-red-900'>Caution: Not for production use.</p>
2022-02-24 04:16:49 +00:00
</div>
2022-02-18 08:56:42 +00:00
</div>
2022-07-26 21:28:46 +00:00
</div>
2022-02-18 08:56:42 +00:00
);
};
2022-01-08 15:11:13 +00:00
export const getServerSideProps: GetServerSideProps = async ({ params }) => {
2022-07-26 21:28:46 +00:00
const metadata: IdPMetadata = {
2024-01-21 01:01:09 +00:00
ssoUrl: config.appUrl,
2022-07-26 21:28:46 +00:00
entityId: config.entityId,
certificate: config.publicKey,
};
return {
props: {
metadata,
params: params ?? {},
2022-07-26 21:28:46 +00:00
},
};
};
2022-02-18 08:56:42 +00:00
export default Home;