Merge branch 'main' of github.com:boxyhq/mock-saml
This commit is contained in:
commit
6b63cc2ea8
@ -1,15 +0,0 @@
|
|||||||
import { PrismaClient } from '@prisma/client';
|
|
||||||
|
|
||||||
let prisma: PrismaClient;
|
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'production') {
|
|
||||||
prisma = new PrismaClient();
|
|
||||||
} else {
|
|
||||||
if (!global.prisma) {
|
|
||||||
global.prisma = new PrismaClient();
|
|
||||||
}
|
|
||||||
|
|
||||||
prisma = global.prisma;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default prisma;
|
|
||||||
2407
package-lock.json
generated
2407
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -8,14 +8,12 @@
|
|||||||
"lint": "next lint"
|
"lint": "next lint"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@prisma/client": "^3.7.0",
|
|
||||||
"axios": "^0.24.0",
|
"axios": "^0.24.0",
|
||||||
"next": "12.1.0",
|
"next": "12.1.0",
|
||||||
"node-fetch": "^3.2.0",
|
"node-fetch": "^3.2.0",
|
||||||
"rambda": "^7.0.2",
|
"rambda": "^7.0.2",
|
||||||
"react": "17.0.2",
|
"react": "17.0.2",
|
||||||
"react-dom": "17.0.2",
|
"react-dom": "17.0.2",
|
||||||
"rsuite": "^5.5.2",
|
|
||||||
"webpack-filter-warnings-plugin": "^1.2.1",
|
"webpack-filter-warnings-plugin": "^1.2.1",
|
||||||
"xml2js": "^0.4.23",
|
"xml2js": "^0.4.23",
|
||||||
"xmlbuilder": "^15.1.1"
|
"xmlbuilder": "^15.1.1"
|
||||||
|
|||||||
@ -1,8 +1,5 @@
|
|||||||
import { PrismaClient } from '@prisma/client';
|
|
||||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
|
||||||
|
|
||||||
type User = {
|
type User = {
|
||||||
id: number;
|
id: number;
|
||||||
first_name: string;
|
first_name: string;
|
||||||
|
|||||||
@ -1,8 +1,5 @@
|
|||||||
import { PrismaClient } from '@prisma/client';
|
|
||||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
|
||||||
|
|
||||||
type User = {
|
type User = {
|
||||||
id: number,
|
id: number,
|
||||||
first_name: string,
|
first_name: string,
|
||||||
|
|||||||
@ -1,12 +1,14 @@
|
|||||||
import type { GetServerSideProps } from 'next';
|
import type { GetServerSideProps } from 'next';
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { AuthNRequest } from '../../types'
|
import { AuthNRequest } from '../../types'
|
||||||
import { extractSAMLRequestAttributes } from '../../utils'
|
import { extractSAMLRequestAttributes, createSAMLResponse } from '../../utils'
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async ({query, params}) => {
|
export const getServerSideProps: GetServerSideProps = async ({query, params}) => {
|
||||||
const relayState = query.RelayState as string;
|
const relayState = query.RelayState as string;
|
||||||
const samlRequest = query.SAMLRequest as string;
|
const samlRequest = query.SAMLRequest as string;
|
||||||
|
|
||||||
|
console.log(await createSAMLResponse())
|
||||||
|
|
||||||
const attributes = await extractSAMLRequestAttributes(samlRequest);
|
const attributes = await extractSAMLRequestAttributes(samlRequest);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -1,25 +0,0 @@
|
|||||||
generator client {
|
|
||||||
provider = "prisma-client-js"
|
|
||||||
}
|
|
||||||
|
|
||||||
datasource db {
|
|
||||||
provider = "postgresql"
|
|
||||||
url = env("DATABASE_URL")
|
|
||||||
}
|
|
||||||
|
|
||||||
model User {
|
|
||||||
id Int @id @default(autoincrement())
|
|
||||||
first_name String
|
|
||||||
last_name String
|
|
||||||
email String
|
|
||||||
}
|
|
||||||
|
|
||||||
model App {
|
|
||||||
id String @id @default(uuid())
|
|
||||||
name String
|
|
||||||
description String?
|
|
||||||
certificate String?
|
|
||||||
acs_url String
|
|
||||||
entity_id String
|
|
||||||
}
|
|
||||||
|
|
||||||
105
utils/index.ts
105
utils/index.ts
@ -5,6 +5,7 @@ import xml2js from 'xml2js';
|
|||||||
import { User } from '../types';
|
import { User } from '../types';
|
||||||
import {promisify} from 'util';
|
import {promisify} from 'util';
|
||||||
import zlib from 'zlib';
|
import zlib from 'zlib';
|
||||||
|
import xmlbuilder from 'xmlbuilder';
|
||||||
|
|
||||||
const inflateRawSync = promisify(zlib.inflateRawSync)
|
const inflateRawSync = promisify(zlib.inflateRawSync)
|
||||||
|
|
||||||
@ -67,28 +68,100 @@ const extractCert = (certificate: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Create SAMLResponse
|
// Create SAMLResponse
|
||||||
const createSAMLResponse = async (user: User): Promise<string> => {
|
const createSAMLResponse = async (): Promise<string> => {
|
||||||
|
const idpIdentityId = 'urn:dev-tyj7qyzz.auth0.com';
|
||||||
|
const audience = 'https://saml.boxyhq.com';
|
||||||
|
const acsUrl = 'http://localhost:3000/sso/acs';
|
||||||
|
|
||||||
|
const user: User = {
|
||||||
|
id: '1',
|
||||||
|
email: 'kiran@boxyhq.com',
|
||||||
|
firstName: 'Kiran',
|
||||||
|
lastName: 'K',
|
||||||
|
}
|
||||||
|
|
||||||
return "";
|
const nodes = {
|
||||||
|
'samlp:Response':{
|
||||||
|
'@xmlns:samlp': 'urn:oasis:names:tc:SAML:2.0:protocol',
|
||||||
|
'@ID': '_dde944f3d9cb96238b0c',
|
||||||
|
'saml:Issuer': {
|
||||||
|
'@xmlns:saml': 'urn:oasis:names:tc:SAML:2.0:assertion',
|
||||||
|
'#text': idpIdentityId,
|
||||||
|
},
|
||||||
|
'samlp:Status': {
|
||||||
|
'samlp:StatusCode': {
|
||||||
|
'@Value': 'urn:oasis:names:tc:SAML:2.0:status:Success'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'saml:Assertion': {
|
||||||
|
'@xmlns:saml': 'urn:oasis:names:tc:SAML:2.0:assertion',
|
||||||
|
'@Version': '2.0',
|
||||||
|
'@ID': '_bsyl9FgHslMWbBp2tFgM0FBJqWNTd3xd',
|
||||||
|
'@IssueInstant': '2022-02-18T06:24:29.856Z',
|
||||||
|
'saml:Issuer': {
|
||||||
|
'#text': idpIdentityId,
|
||||||
|
},
|
||||||
|
'saml:Subject': {
|
||||||
|
'saml:NameID': {
|
||||||
|
'@Format': 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified',
|
||||||
|
'#text': 'google-oauth2|108149256146623609101',
|
||||||
|
},
|
||||||
|
'saml:SubjectConfirmation': {
|
||||||
|
'@Method': 'urn:oasis:names:tc:SAML:2.0:cm:bearer',
|
||||||
|
'saml:SubjectConfirmationData': {
|
||||||
|
'@NotOnOrAfter': '2022-02-18T07:24:29.856Z',
|
||||||
|
'@Recipient': acsUrl,
|
||||||
|
'@InResponseTo': '_e427c05d2462c8c2550e'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'saml:Conditions': {
|
||||||
|
'@NotBefore': '2022-02-18T06:24:29.856Z',
|
||||||
|
'@NotOnOrAfter': '2022-02-18T07:24:29.856Z',
|
||||||
|
'saml:AudienceRestriction': {
|
||||||
|
'saml:Audience': {
|
||||||
|
'#text': audience,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'saml:AuthnStatement': {
|
||||||
|
'@AuthnInstant': '2022-02-18T06:24:29.856Z',
|
||||||
|
'@SessionIndex': '_YIlFoNFzLMDYxdwf-T_BuimfkGa5qhKg',
|
||||||
|
'saml:AuthnContext': {
|
||||||
|
'saml:AuthnContextClassRef': {
|
||||||
|
'#text': 'urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'saml:AttributeStatement': {
|
||||||
|
'@xmlns:xs': 'http://www.w3.org/2001/XMLSchema',
|
||||||
|
'@xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
|
||||||
|
'saml:Attribute': {
|
||||||
|
'@Name': 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress',
|
||||||
|
'@NameFormat': 'urn:oasis:names:tc:SAML:2.0:attrname-format:uri',
|
||||||
|
'saml:AttributeValue': {
|
||||||
|
'@xsi:type': 'xs:string',
|
||||||
|
'#text': user.email,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// const xmlPath = path.join('data', 'saml-response.xml');
|
// @ts-ignore
|
||||||
// const xml = await fs.readFile(xmlPath, 'utf8');
|
'saml:Attribute': {
|
||||||
|
'@Name': 'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress',
|
||||||
|
'@NameFormat': 'urn:oasis:names:tc:SAML:2.0:attrname-format:uri',
|
||||||
|
'saml:AttributeValue': {
|
||||||
|
'@xsi:type': 'xs:string',
|
||||||
|
'#text': user.id
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// return xml
|
return xmlbuilder.create(nodes).end({ pretty: true});
|
||||||
// .replace(
|
|
||||||
// /idp_entity_id/g,
|
|
||||||
// 'https://accounts.google.com/o/saml2?idpid=C02frd9s1'
|
|
||||||
// )
|
|
||||||
// .replace('sp_acs_url', 'some-url')
|
|
||||||
// .replace(/user_email/g, 'kiran@demo.com')
|
|
||||||
// .replace('user_firstName', 'Kiran')
|
|
||||||
// .replace('user_lastName', 'K');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
|
||||||
// base64 encode
|
|
||||||
|
|
||||||
export const createResponseForm = (relayState: string, samlResponse: string, acsUrl: string) => {
|
export const createResponseForm = (relayState: string, samlResponse: string, acsUrl: string) => {
|
||||||
const formElements = [
|
const formElements = [
|
||||||
'<!DOCTYPE html>',
|
'<!DOCTYPE html>',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user