0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-04-07 23:01:25 -05:00

fix(core): fix SAML validator setup (#6961)

This commit is contained in:
Darcy Ye 2025-01-21 11:46:46 +08:00 committed by GitHub
parent d2468683c8
commit b88a07598e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -59,21 +59,6 @@ type SamlServiceProviderConfig = {
certificate?: string;
};
// Used to check whether xml content is valid in format.
saml.setSchemaValidator({
validate: async (xmlContent: string) => {
try {
XMLValidator.validate(xmlContent, {
allowBooleanAttributes: true,
});
return true;
} catch {
return false;
}
},
});
class SamlApplicationConfig {
constructor(private readonly _details: SamlApplicationDetails) {}
@ -140,11 +125,13 @@ export class SamlApplication {
public get idp(): saml.IdentityProviderInstance {
this._idp ||= this.buildSamlIdentityProvider();
this.setSchemaValidator();
return this._idp;
}
public get sp(): saml.ServiceProviderInstance {
this._sp ||= this.buildSamlServiceProvider();
this.setSchemaValidator();
return this._sp;
}
@ -472,6 +459,23 @@ export class SamlApplication {
);
};
// Used to check whether xml content is valid in format.
private setSchemaValidator() {
saml.setSchemaValidator({
validate: async (xmlContent: string) => {
try {
XMLValidator.validate(xmlContent, {
allowBooleanAttributes: true,
});
return true;
} catch {
return false;
}
},
});
}
private buildIdpConfig(): SamlIdentityProviderConfig {
return {
entityId: buildSamlIdentityProviderEntityId(this.tenantEndpoint, this.samlApplicationId),