This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
nodeparse2.js
90 lines (55 loc) · 2.47 KB
/
nodeparse2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var users = require('./users.json')
var oauth2Grants = require('./oauth2PermissionGrants.json')
var spns = require('./servicePrincipals.json')
var applications = require('./applications-save.json')
const { getWebSitesName } = require('./src/dnslook')
main()
async function main () {
oauth2Grants.map((item) => {
var match = users.find((user) => user.id == item.principalId)
item.userPrincipalName = match?.userPrincipalName || null
return item
} )
oauth2Grants.map((item) => {
var match = spns.find((spn) => spn.id == item.resourceId)
item.resourceDisplayName = match.displayName || null
})
spns.map( (item) =>{
var pw = applications.find((spn) => spn.appId == item.appId )
item.ApplicationHasPassword = pw?.passwordCredentials || item.passwordCredentials
item.ApplicationHasPublicClient = pw?.isFallbackPublicClient || ""
item.ApplicationHasRequiredAccess = pw?.requiredResourceAccess.map((res) => {
var spm =spns.find((spn) => spn.appId == res.resourceAppId)
res.resourceAccess = res?.resourceAccess || []
if (spm) {
return res?.resourceAccess.map(({id}) => {
spm.appRoles = spm?.appRoles || []
//console.log(spm.appRoles.length)
spm.oauth2PermissionScopes = spm?.oauth2PermissionScopes || []
var oauth2R = spm?.oauth2PermissionScopes.find((role) => role.id == id)
if (oauth2R) {
oauth2R.resource = spm?.appDisplayName || []
return oauth2R
}
}) || []
}
})
delete item.appRoles; delete item.oauth2PermissionScopes
})
var rs = []
spns.map( spn => {
spn.replyUrls.filter(item => item.match('azurewebsites.net')).forEach(item => {
rs.push(getWebSitesName({fqdn:item,id:spn.id}))
})
})
var s= await Promise.all(rs)
var dangl = s.filter(item => item.failed == true)
spns.map(item => {
item.danglingRedirect= dangl.filter(spn => spn.id == item.id) || undefined || {}
})
/* spns.push(require('./material/doNotRemove.json')[2])
spns.reverse() */
// console.log(oauth2Grants)
require('fs').writeFileSync('./material/servicePrincipalsUP.json',JSON.stringify(spns))
require('fs').writeFileSync('./material/oauth2PermissionGrantsUP.json',JSON.stringify(oauth2Grants))
}