ukamf-entity.js 959 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. const entityId = this.data.$.entityID
  12. let cert = _.get(signingKey, [
  13. 'ds:KeyInfo',
  14. 0,
  15. 'ds:X509Data',
  16. 0,
  17. 'ds:X509Certificate',
  18. 0
  19. ])
  20. if (!cert) {
  21. throw new Error('no cert')
  22. }
  23. cert = cert.replace(/\s/g, '')
  24. let entryPoint = idp.SingleSignOnService.find(
  25. sso =>
  26. _.get(sso, ['$', 'Binding']) ===
  27. 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect'
  28. )
  29. entryPoint = _.get(entryPoint, ['$', 'Location'])
  30. if (!entryPoint) {
  31. throw new Error('no entryPoint')
  32. }
  33. return {
  34. cert,
  35. entityId,
  36. entryPoint
  37. }
  38. }
  39. }
  40. module.exports = UKAMFEntity