{"version":3,"file":"IdpInfo.mjs","sources":["../../../../../../../../web/src/adminPortal/sso/IdpInfo.ts"],"sourcesContent":["import { RequireAllOrNone } from 'type-fest';\n\nimport { OidcKnownIdp, SamlKnownIdp } from '../../utils/KnownIdp';\nimport { ConnectionType } from '../utils/ConnectionType';\nimport {\n  ExternalTaggedConnection,\n  OIDCTaggedConnection,\n  SAMLTaggedConnection,\n  TaggedConnection,\n} from './TaggedConnection';\n\nexport type SamlSetupStep = 'createApplication' | 'copyToIdp' | 'copyFromIdp' | 'attributeMapping';\n\nexport type SamlIdpValue = 'ssoUrl' | 'entityId' | 'certificate';\n\nexport type OidcSetupStep = 'createApplication' | 'copyToIdp' | 'copyFromIdp';\n\nexport type SamlSupportedIdp = 'okta' | 'microsoft-entra' | 'google-workspace';\nexport type OidcSupportedIdp = 'okta' | 'microsoft-entra';\nexport type SamlSupportedManualConfigurationIdp = 'microsoft-entra' | 'google-workspace';\nexport type SamlSupportedAttributeMappingIdp = 'okta' | 'microsoft-entra' | 'google-workspace';\n\nexport type SamlIdpInfo = {\n  displayName: string;\n  copyToOrFromIdpDisplayName: string;\n  setupOrder: SamlSetupStep[];\n  idpValueOrder: SamlIdpValue[];\n  acsUrlLabel: string;\n  audienceUriLabel: string;\n  idpSsoUrlLabel: string;\n  idpEntityIdLabel: string;\n  x509CertificateLabel: string;\n  metadataUrlLabel: string | false;\n  nameIdFormatLabel: string;\n  nameIdFormatValue: string;\n  attributeMappingLabel: string;\n};\n\ninterface IssuerTransformer {\n  issuerDerivedLabel: string;\n  transformInputToIssuer?: (input: string) => string;\n  extractIssuerFromInput?: (input: string) => string | undefined;\n}\n\nexport type OidcIdpInfo = {\n  displayName: string;\n  copyToOrFromIdpDisplayName: string;\n  setupOrder: OidcSetupStep[];\n  redirectUrlLabel: string;\n  clientIdLabel: string;\n  clientSecretLabel: string;\n  issuerLabel: string;\n} & RequireAllOrNone<IssuerTransformer, keyof IssuerTransformer>;\n\nexport const samlIdpMap = {\n  generic: {\n    displayName: 'Custom SAML',\n    copyToOrFromIdpDisplayName: 'your IdP',\n    setupOrder: ['copyToIdp', 'attributeMapping', 'copyFromIdp'],\n    idpValueOrder: ['ssoUrl', 'entityId', 'certificate'],\n    acsUrlLabel: 'ACS URL (Reply URL)',\n    audienceUriLabel: 'Audience URI (SP Entity ID)',\n    idpSsoUrlLabel: 'IdP Sign-on URL',\n    idpEntityIdLabel: 'IdP Entity ID',\n    x509CertificateLabel: 'x509 Certificate (PEM Format)',\n    metadataUrlLabel: 'Metadata URL',\n    nameIdFormatLabel: 'Name ID Format',\n    nameIdFormatValue: 'Primary Email Address',\n    attributeMappingLabel: 'Attribute Mapping',\n  },\n  'microsoft-entra': {\n    displayName: 'Entra SAML',\n    copyToOrFromIdpDisplayName: 'Entra',\n    setupOrder: ['createApplication', 'copyToIdp', 'attributeMapping', 'copyFromIdp'],\n    idpValueOrder: ['ssoUrl', 'entityId', 'certificate'],\n    acsUrlLabel: 'Reply URL (Assertion Consumer Service URL)',\n    audienceUriLabel: 'Identifier (Entity ID)',\n    idpSsoUrlLabel: 'Login Url',\n    idpEntityIdLabel: 'Microsoft Entra Identifier',\n    x509CertificateLabel: 'PEM Certificate',\n    metadataUrlLabel: 'App Federation Metadata Url',\n    nameIdFormatLabel: 'Unique User Identifier (Name ID) Format',\n    nameIdFormatValue: 'user.primaryauthoritativeemail',\n    attributeMappingLabel: 'Claim Names',\n  },\n  okta: {\n    displayName: 'Okta SAML',\n    copyToOrFromIdpDisplayName: 'Okta',\n    setupOrder: ['createApplication', 'copyToIdp', 'attributeMapping', 'copyFromIdp'],\n    idpValueOrder: ['ssoUrl', 'entityId', 'certificate'],\n    acsUrlLabel: 'Single sign-on URL',\n    audienceUriLabel: 'Audience URI (SP Entity ID)',\n    idpSsoUrlLabel: 'Sign-on URL',\n    idpEntityIdLabel: 'Issuer',\n    x509CertificateLabel: 'Signing Certificate',\n    metadataUrlLabel: 'Metadata URL',\n    nameIdFormatLabel: 'Name ID Format',\n    nameIdFormatValue: 'EmailAddress',\n    attributeMappingLabel: 'Attribute Statements',\n  },\n  'google-workspace': {\n    displayName: 'Google SAML',\n    copyToOrFromIdpDisplayName: 'Google',\n    setupOrder: ['createApplication', 'copyFromIdp', 'copyToIdp', 'attributeMapping'],\n    idpValueOrder: ['entityId', 'ssoUrl', 'certificate'],\n    acsUrlLabel: 'ACS URL',\n    audienceUriLabel: 'Entity ID',\n    idpSsoUrlLabel: 'SSO URL',\n    idpEntityIdLabel: 'Entity ID',\n    x509CertificateLabel: 'Certificate',\n    metadataUrlLabel: false,\n    nameIdFormatLabel: 'NameID Format',\n    nameIdFormatValue: 'EMAIL; Basic Information > Primary email',\n    attributeMappingLabel: 'Attribute Mapping',\n  },\n} as const satisfies Record<SamlKnownIdp, SamlIdpInfo>;\n\nexport const oidcIdpMap = {\n  generic: {\n    displayName: 'Custom OIDC',\n    copyToOrFromIdpDisplayName: 'your IdP',\n    setupOrder: ['copyToIdp', 'copyFromIdp'],\n    redirectUrlLabel: 'Redirect URI',\n    clientIdLabel: 'Client ID',\n    clientSecretLabel: 'Client Secret',\n    issuerLabel: 'Issuer',\n  },\n  'microsoft-entra': {\n    displayName: 'Entra OIDC',\n    copyToOrFromIdpDisplayName: 'Entra',\n    setupOrder: ['createApplication', 'copyToIdp', 'copyFromIdp'],\n    redirectUrlLabel: 'Redirect URI',\n    clientIdLabel: 'Application (Client) ID',\n    clientSecretLabel: 'Client Secret',\n    issuerLabel: 'Issuer',\n    issuerDerivedLabel: 'Directory (tenant) ID',\n    extractIssuerFromInput: (input) => {\n      const match = input.match(/^https:\\/\\/login\\.microsoftonline\\.com\\/(.+)\\/v2\\.0$/);\n      return match?.[1];\n    },\n    transformInputToIssuer: (id) => `https://login.microsoftonline.com/${id}/v2.0`,\n  },\n  okta: {\n    displayName: 'Okta OIDC',\n    copyToOrFromIdpDisplayName: 'Okta',\n    setupOrder: ['createApplication', 'copyToIdp', 'copyFromIdp'],\n    redirectUrlLabel: 'Sign-in Redirect URI',\n    clientIdLabel: 'Client ID',\n    clientSecretLabel: 'Client Secret',\n    issuerLabel: 'Okta URL (Issuer)',\n  },\n} as const satisfies Record<OidcKnownIdp, OidcIdpInfo>;\n\ntype SamlTaggedIdpInfo = {\n  idp: SamlIdpInfo;\n  type: 'saml';\n};\n\ntype OidcTaggedIdpInfo = {\n  idp: OidcIdpInfo;\n  type: 'oidc';\n};\n\nexport type TaggedIdpInfo = SamlTaggedIdpInfo | OidcTaggedIdpInfo;\n\ntype IdpInfoReturnType<TConnectionType extends ConnectionType> = TaggedIdpInfo & {\n  type: TConnectionType;\n};\n\nexport const getIdpInfo = <TConnectionType extends ConnectionType>(\n  idp: string,\n  type: TConnectionType,\n): IdpInfoReturnType<TConnectionType> => {\n  if (type === 'saml') {\n    const idpKey = idp in samlIdpMap ? (idp as SamlKnownIdp) : 'generic';\n    return { idp: samlIdpMap[idpKey], type } as IdpInfoReturnType<TConnectionType>;\n  } else {\n    const idpKey = idp in oidcIdpMap ? (idp as OidcKnownIdp) : 'generic';\n    return { idp: oidcIdpMap[idpKey], type } as IdpInfoReturnType<TConnectionType>;\n  }\n};\n\ntype IdpAndConnectionInfoReturnType<TConnectionType extends ConnectionType> = (\n  | (SamlTaggedIdpInfo & { connection: SAMLTaggedConnection })\n  | (OidcTaggedIdpInfo & { connection: OIDCTaggedConnection })\n  | { idp: undefined; type: 'external'; connection: ExternalTaggedConnection }\n) & { type: TConnectionType };\n\nexport const getIdpAndConnectionInfo = <TConnectionType extends ConnectionType>(\n  connection: TaggedConnection & { connectionType: TConnectionType },\n): IdpAndConnectionInfoReturnType<TConnectionType> => {\n  if (connection.connectionType === 'external') {\n    return {\n      idp: undefined,\n      type: 'external',\n      connection: connection as ExternalTaggedConnection,\n    } as IdpAndConnectionInfoReturnType<TConnectionType>;\n  }\n\n  return {\n    ...getIdpInfo(\n      (connection as SAMLTaggedConnection | OIDCTaggedConnection).identity_provider,\n      connection.connectionType,\n    ),\n    connection,\n  } as IdpAndConnectionInfoReturnType<TConnectionType>;\n};\n\nexport const typeToUserFriendlyName = (type: ConnectionType): string => {\n  if (type === 'saml') {\n    return 'SAML';\n  } else if (type === 'oidc') {\n    return 'OIDC';\n  } else {\n    return 'External';\n  }\n};\n"],"names":["samlIdpMap","generic","displayName","copyToOrFromIdpDisplayName","setupOrder","idpValueOrder","acsUrlLabel","audienceUriLabel","idpSsoUrlLabel","idpEntityIdLabel","x509CertificateLabel","metadataUrlLabel","nameIdFormatLabel","nameIdFormatValue","attributeMappingLabel","okta","oidcIdpMap","redirectUrlLabel","clientIdLabel","clientSecretLabel","issuerLabel","issuerDerivedLabel","extractIssuerFromInput","input","match","transformInputToIssuer","id","getIdpInfo","idp","type","idpKey","getIdpAndConnectionInfo","connection","connectionType","undefined","identity_provider","typeToUserFriendlyName"],"mappings":"MAsDaA,UAAAA,GAAa;IACxBC,OAAAA,EAAS;QACPC,WAAAA,EAAa,aAAA;QACbC,0BAAAA,EAA4B,UAAA;QAC5BC,UAAAA,EAAY;AAAC,YAAA,WAAA;AAAa,YAAA,kBAAA;AAAoB,YAAA;AAAc,SAAA;QAC5DC,aAAAA,EAAe;AAAC,YAAA,QAAA;AAAU,YAAA,UAAA;AAAY,YAAA;AAAc,SAAA;QACpDC,WAAAA,EAAa,qBAAA;QACbC,gBAAAA,EAAkB,6BAAA;QAClBC,cAAAA,EAAgB,iBAAA;QAChBC,gBAAAA,EAAkB,eAAA;QAClBC,oBAAAA,EAAsB,+BAAA;QACtBC,gBAAAA,EAAkB,cAAA;QAClBC,iBAAAA,EAAmB,gBAAA;QACnBC,iBAAAA,EAAmB,uBAAA;QACnBC,qBAAAA,EAAuB;AACzB,KAAA;IACA,iBAAA,EAAmB;QACjBZ,WAAAA,EAAa,YAAA;QACbC,0BAAAA,EAA4B,OAAA;QAC5BC,UAAAA,EAAY;AAAC,YAAA,mBAAA;AAAqB,YAAA,WAAA;AAAa,YAAA,kBAAA;AAAoB,YAAA;AAAc,SAAA;QACjFC,aAAAA,EAAe;AAA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