2019-11-21 12:42:45 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const _ = require('lodash')
|
|
|
|
|
|
|
|
class UKAMFEntity {
|
|
|
|
constructor(data) {
|
|
|
|
this.data = data
|
|
|
|
}
|
|
|
|
|
|
|
|
getSamlConfig() {
|
2021-05-11 14:08:42 +00:00
|
|
|
let hiddenIdP = false
|
2019-11-21 12:42:45 +00:00
|
|
|
const idp = this.data.IDPSSODescriptor[0]
|
2021-05-11 14:08:42 +00:00
|
|
|
const idpMetaData =
|
|
|
|
_.get(this.data, [
|
|
|
|
'Extensions',
|
|
|
|
0,
|
|
|
|
'mdattr:EntityAttributes',
|
|
|
|
0,
|
|
|
|
'saml:Attribute',
|
|
|
|
]) || []
|
|
|
|
idpMetaData.forEach(data => {
|
|
|
|
const value = _.get(data, ['saml:AttributeValue', 0])
|
|
|
|
if (
|
|
|
|
value === 'http://refeds.org/category/hide-from-discovery' ||
|
|
|
|
value === 'https://refeds.org/category/hide-from-discovery'
|
|
|
|
) {
|
|
|
|
hiddenIdP = true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-11-21 12:42:45 +00:00
|
|
|
const keys = idp.KeyDescriptor
|
2021-05-11 14:08:42 +00:00
|
|
|
|
2019-12-09 15:09:32 +00:00
|
|
|
const signingKey =
|
|
|
|
keys.length === 1
|
|
|
|
? keys[0]
|
|
|
|
: keys.find(key => _.get(key, ['$', 'use']) === 'signing')
|
2019-11-27 15:05:26 +00:00
|
|
|
const entityId = this.data.$.entityID
|
2019-11-21 12:42:45 +00:00
|
|
|
|
|
|
|
let cert = _.get(signingKey, [
|
|
|
|
'ds:KeyInfo',
|
|
|
|
0,
|
|
|
|
'ds:X509Data',
|
|
|
|
0,
|
|
|
|
'ds:X509Certificate',
|
2021-04-27 07:52:58 +00:00
|
|
|
0,
|
2019-11-21 12:42:45 +00:00
|
|
|
])
|
|
|
|
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 15:05:26 +00:00
|
|
|
entityId,
|
2021-04-27 07:52:58 +00:00
|
|
|
entryPoint,
|
2021-05-11 14:08:42 +00:00
|
|
|
hiddenIdP,
|
2019-11-21 12:42:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = UKAMFEntity
|