mirror of
https://github.com/logto-io/logto.git
synced 2025-01-27 21:39:16 -05:00
refactor(core): simplify the saml getIssuer method (#4942)
simplify the saml getIssuer method
This commit is contained in:
parent
9a91c0ad10
commit
6785cfcd3e
2 changed files with 19 additions and 26 deletions
|
@ -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<SamlIdentityProviderMetadata> {
|
||||
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<SamlIdentityProviderMetadata> {
|
||||
if (this._samlIdpMetadata) {
|
||||
return this._samlIdpMetadata;
|
||||
}
|
||||
|
||||
const identityProvider = await this.getIdentityProvider();
|
||||
this._samlIdpMetadata = parseXmlMetadata(identityProvider);
|
||||
return this._samlIdpMetadata;
|
||||
}
|
||||
}
|
||||
|
||||
export default SamlConnector;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue