ukamf-entity.js 1011 B

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