parse SAML req
This commit is contained in:
parent
d455e9ae0a
commit
e25bb86413
@ -20,10 +20,10 @@ export default async function handler(
|
|||||||
async function processSAMLRequest() {
|
async function processSAMLRequest() {
|
||||||
const relayState = <string>req.query.RelayState;
|
const relayState = <string>req.query.RelayState;
|
||||||
const samlRequest = <string>req.query.SAMLRequest;
|
const samlRequest = <string>req.query.SAMLRequest;
|
||||||
|
const { id, audience, acsUrl, providerName } = await extractSAMLRequestAttributes(samlRequest);
|
||||||
|
|
||||||
const idpIdentityId = config.entityId;
|
const idpIdentityId = audience;
|
||||||
const audience = config.entityId;
|
// const audience = config.entityId;
|
||||||
const acsUrl = 'http://localhost:3000/sso/acs'; // TODO: Fetch acsUrl from SAMLRequest
|
|
||||||
|
|
||||||
const user: User = {
|
const user: User = {
|
||||||
id: '1',
|
id: '1',
|
||||||
|
|||||||
@ -1,10 +1,8 @@
|
|||||||
import { promises as fs } from 'fs';
|
import xml2js from "xml2js";
|
||||||
import path from 'path';
|
import { promisify } from "util";
|
||||||
import xml2js from 'xml2js';
|
import { inflateRaw } from "zlib";
|
||||||
import {promisify} from 'util';
|
|
||||||
import zlib from 'zlib';
|
|
||||||
|
|
||||||
const inflateRawSync = promisify(zlib.inflateRawSync)
|
const inflateRawAsync = promisify(inflateRaw);
|
||||||
|
|
||||||
// Parse XML
|
// Parse XML
|
||||||
const parseXML = (xml: string): Promise<Record<string, any>> => {
|
const parseXML = (xml: string): Promise<Record<string, any>> => {
|
||||||
@ -21,15 +19,18 @@ const parseXML = (xml: string): Promise<Record<string, any>> => {
|
|||||||
|
|
||||||
// Parse SAMLRequest attributes
|
// Parse SAMLRequest attributes
|
||||||
const extractSAMLRequestAttributes = async (samlRequest: string) => {
|
const extractSAMLRequestAttributes = async (samlRequest: string) => {
|
||||||
// const request = await inflateRawSync(Buffer.from(samlRequest, 'base64')).toString();
|
const request = (
|
||||||
// const result = await parseXML(request);
|
await inflateRawAsync(Buffer.from(samlRequest, "base64"))
|
||||||
|
).toString();
|
||||||
// const attributes = result['samlp:AuthnRequest']['$'];
|
const result = await parseXML(request);
|
||||||
|
|
||||||
|
const attributes = result["samlp:AuthnRequest"]["$"];
|
||||||
|
const issuer = result["samlp:AuthnRequest"]["saml:Issuer"];
|
||||||
return {
|
return {
|
||||||
id: '123',
|
id: attributes.ID,
|
||||||
acsUrl: 'https://hookb.in/NOrYqkDLnXse8mNNlDXx',
|
acsUrl: attributes.AssertionConsumerServiceURL,
|
||||||
providerName: 'BoxyHQ',
|
providerName: attributes.ProviderName,
|
||||||
|
audience: issuer[0]["_"],
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user