2019-11-21 07:42:45 -05:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const _ = require('lodash')
|
|
|
|
|
|
|
|
class UKAMFEntity {
|
|
|
|
constructor(data) {
|
|
|
|
this.data = data
|
|
|
|
}
|
|
|
|
|
|
|
|
getSamlConfig() {
|
|
|
|
const idp = this.data.IDPSSODescriptor[0]
|
|
|
|
const keys = idp.KeyDescriptor
|
2019-12-09 10:09:32 -05:00
|
|
|
const signingKey =
|
|
|
|
keys.length === 1
|
|
|
|
? keys[0]
|
|
|
|
: keys.find(key => _.get(key, ['$', 'use']) === 'signing')
|
2019-11-27 10:05:26 -05:00
|
|
|
const entityId = this.data.$.entityID
|
2019-11-21 07:42:45 -05:00
|
|
|
|
|
|
|
let cert = _.get(signingKey, [
|
|
|
|
'ds:KeyInfo',
|
|
|
|
0,
|
|
|
|
'ds:X509Data',
|
|
|
|
0,
|
|
|
|
'ds:X509Certificate',
|
|
|
|
0
|
|
|
|
])
|
|
|
|
if (!cert) {
|
|
|
|
throw new Error('no cert')
|
|
|
|
}
|
|
|
|
cert = cert.replace(/\s/g, '')
|
|
|
|
|
|
|
|
let entryPoint = idp.SingleSignOnService.find(
|
|
|
|
sso =>
|
|
|
|
_.get(sso, ['$', 'Binding']) ===
|
|
|
|
'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect'
|
|
|
|
)
|
|
|
|
entryPoint = _.get(entryPoint, ['$', 'Location'])
|
|
|
|
if (!entryPoint) {
|
|
|
|
throw new Error('no entryPoint')
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
cert,
|
2019-11-27 10:05:26 -05:00
|
|
|
entityId,
|
2019-11-21 07:42:45 -05:00
|
|
|
entryPoint
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = UKAMFEntity
|