ukamf-entity.js 901 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict'
  2. const _ = require('lodash')
  3. class UKAMFEntity {
  4. constructor(data) {
  5. this.data = data
  6. }
  7. getSamlConfig() {
  8. const idp = this.data.IDPSSODescriptor[0]
  9. const keys = idp.KeyDescriptor
  10. const signingKey = keys.find(key => _.get(key, ['$', 'use']) === 'signing')
  11. let cert = _.get(signingKey, [
  12. 'ds:KeyInfo',
  13. 0,
  14. 'ds:X509Data',
  15. 0,
  16. 'ds:X509Certificate',
  17. 0
  18. ])
  19. if (!cert) {
  20. throw new Error('no cert')
  21. }
  22. cert = cert.replace(/\s/g, '')
  23. let entryPoint = idp.SingleSignOnService.find(
  24. sso =>
  25. _.get(sso, ['$', 'Binding']) ===
  26. 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect'
  27. )
  28. entryPoint = _.get(entryPoint, ['$', 'Location'])
  29. if (!entryPoint) {
  30. throw new Error('no entryPoint')
  31. }
  32. return {
  33. cert,
  34. entryPoint
  35. }
  36. }
  37. }
  38. module.exports = UKAMFEntity