From 6785cfcd3e50fd64fb88e5d6eb3943c1d8964d82 Mon Sep 17 00:00:00 2001 From: simeng-li Date: Thu, 23 Nov 2023 13:32:00 +0800 Subject: [PATCH] refactor(core): simplify the saml getIssuer method (#4942) simplify the saml getIssuer method --- packages/core/src/sso/SamlConnector/index.ts | 34 +++++++++---------- .../core/src/sso/SamlSsoConnector/index.ts | 11 ++---- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/packages/core/src/sso/SamlConnector/index.ts b/packages/core/src/sso/SamlConnector/index.ts index 2ff671e68..c9b3be42a 100644 --- a/packages/core/src/sso/SamlConnector/index.ts +++ b/packages/core/src/sso/SamlConnector/index.ts @@ -154,6 +154,23 @@ class SamlConnector { } } + /** + * Get SAML IdP config along with parsed metadata from raw SAML SSO connector config. + * + * @remarks If this function can successfully get the SAML metadata, then it guarantees that the SAML identity provider instance is initiated. + * + * @returns Parsed SAML config along with it's parsed metadata. + */ + protected async getSamlIdpMetadata(): Promise { + if (this._samlIdpMetadata) { + return this._samlIdpMetadata; + } + + const identityProvider = await this.getIdentityProvider(); + this._samlIdpMetadata = parseXmlMetadata(identityProvider); + return this._samlIdpMetadata; + } + /** * Get the raw SAML metadata (in XML-format) from the raw SAML SSO connector config. * @@ -222,23 +239,6 @@ class SamlConnector { }); return this._identityProvider; } - - /** - * Get SAML IdP config along with parsed metadata from raw SAML SSO connector config. - * - * @remarks If this function can successfully get the SAML metadata, then it guarantees that the SAML identity provider instance is initiated. - * - * @returns Parsed SAML config along with it's parsed metadata. - */ - private async getSamlIdpMetadata(): Promise { - if (this._samlIdpMetadata) { - return this._samlIdpMetadata; - } - - const identityProvider = await this.getIdentityProvider(); - this._samlIdpMetadata = parseXmlMetadata(identityProvider); - return this._samlIdpMetadata; - } } export default SamlConnector; diff --git a/packages/core/src/sso/SamlSsoConnector/index.ts b/packages/core/src/sso/SamlSsoConnector/index.ts index 8d65ccd65..9075c0624 100644 --- a/packages/core/src/sso/SamlSsoConnector/index.ts +++ b/packages/core/src/sso/SamlSsoConnector/index.ts @@ -38,16 +38,9 @@ export class SamlSsoConnector extends SamlConnector implements SingleSignOn { } async getIssuer() { - const { identityProvider } = await this.getSamlConfig(); + const { entityId } = await this.getSamlIdpMetadata(); - if (!identityProvider?.entityId) { - throw new ConnectorError( - ConnectorErrorCodes.InvalidConfig, - 'Can not get `entityId` from metadata config!' - ); - } - - return identityProvider.entityId; + return entityId; } /**