@@ -51,6 +51,9 @@ const CippAppPermissionBuilder = ({ onSubmit, currentPermissions = {}, isSubmitt
51
51
body : `Are you sure you want to remove ${ servicePrincipal . displayName } ?` ,
52
52
onConfirm : ( ) => {
53
53
setSelectedApp ( newServicePrincipals )
54
+ var updatedPermissions = JSON . parse ( JSON . stringify ( newPermissions ) )
55
+ delete updatedPermissions . Permissions [ appId ]
56
+ setNewPermissions ( updatedPermissions )
54
57
} ,
55
58
} )
56
59
}
@@ -77,6 +80,13 @@ const CippAppPermissionBuilder = ({ onSubmit, currentPermissions = {}, isSubmitt
77
80
78
81
const addPermissionRow = ( servicePrincipal , permissionType , permission ) => {
79
82
var updatedPermissions = JSON . parse ( JSON . stringify ( newPermissions ) )
83
+
84
+ if ( ! updatedPermissions ?. Permissions [ servicePrincipal ] ) {
85
+ updatedPermissions . Permissions [ servicePrincipal ] = {
86
+ applicationPermissions : [ ] ,
87
+ delegatedPermissions : [ ] ,
88
+ }
89
+ }
80
90
var currentPermission = updatedPermissions ?. Permissions [ servicePrincipal ] [ permissionType ]
81
91
var newPermission = [ ]
82
92
if ( currentPermission ) {
@@ -114,6 +124,75 @@ const CippAppPermissionBuilder = ({ onSubmit, currentPermissions = {}, isSubmitt
114
124
} )
115
125
}
116
126
127
+ const generateManifest = ( appDisplayName = 'CIPP-SAM' , prompt = false ) => {
128
+ if ( prompt ) {
129
+ // modal input form for appDisplayName
130
+ ModalService . prompt ( {
131
+ title : 'Generate Manifest' ,
132
+ body : 'Please enter the display name for the application.' ,
133
+ onConfirm : ( value ) => {
134
+ generateManifest ( { appDisplayName : value } )
135
+ } ,
136
+ } )
137
+ } else {
138
+ var manifest = {
139
+ isFallbackPublicClient : true ,
140
+ signInAudience : 'AzureADMultipleOrgs' ,
141
+ displayName : appDisplayName ,
142
+ web : {
143
+ redirectUris : [
144
+ 'https://login.microsoftonline.com/common/oauth2/nativeclient' ,
145
+ 'https://localhost' ,
146
+ 'http://localhost' ,
147
+ 'http://localhost:8400' ,
148
+ ] ,
149
+ } ,
150
+ requiredResourceAccess : [ ] ,
151
+ }
152
+
153
+ selectedApp . map ( ( sp ) => {
154
+ var appRoles = newPermissions ?. Permissions [ sp . appId ] ?. applicationPermissions
155
+ var delegatedPermissions = newPermissions ?. Permissions [ sp . appId ] ?. delegatedPermissions
156
+ var requiredResourceAccess = {
157
+ resourceAppId : sp . appId ,
158
+ resourceAccess : [ ] ,
159
+ }
160
+ appRoles . map ( ( role ) => {
161
+ requiredResourceAccess . resourceAccess . push ( {
162
+ id : role . id ,
163
+ type : 'Role' ,
164
+ } )
165
+ } )
166
+ delegatedPermissions . map ( ( perm ) => {
167
+ // permission not a guid skip
168
+ if ( / ^ [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 12 } $ / i. test ( perm . id ) ) {
169
+ requiredResourceAccess . resourceAccess . push ( {
170
+ id : perm . id ,
171
+ type : 'Scope' ,
172
+ } )
173
+ }
174
+ } )
175
+ if ( requiredResourceAccess . resourceAccess . length > 0 ) {
176
+ manifest . requiredResourceAccess . push ( requiredResourceAccess )
177
+ }
178
+ } )
179
+
180
+ var fileName = `${ appDisplayName . replace ( ' ' , '-' ) } .json`
181
+ if ( appDisplayName === 'CIPP-SAM' ) {
182
+ fileName = 'SAMManifest.json'
183
+ }
184
+
185
+ var blob = new Blob ( [ JSON . stringify ( manifest , null , 2 ) ] , { type : 'application/json' } )
186
+ var url = URL . createObjectURL ( blob )
187
+ var a = document . createElement ( 'a' )
188
+ a . href = url
189
+ a . download = `${ fileName } .json`
190
+ a . click ( )
191
+ }
192
+ }
193
+
194
+ const importManifest = ( ) => { }
195
+
117
196
useEffect ( ( ) => {
118
197
try {
119
198
var initialAppIds = Object . keys ( currentPermissions ?. Permissions )
@@ -126,6 +205,15 @@ const CippAppPermissionBuilder = ({ onSubmit, currentPermissions = {}, isSubmitt
126
205
( sp ) => sp ?. appId === '00000003-0000-0000-c000-000000000000' ,
127
206
)
128
207
setSelectedApp ( [ microsoftGraph ] )
208
+ setNewPermissions ( {
209
+ Permissions : {
210
+ '00000003-0000-0000-c000-000000000000' : {
211
+ applicationPermissions : [ ] ,
212
+ delegatedPermissions : [ ] ,
213
+ } ,
214
+ } ,
215
+ } )
216
+ setPermissionsImported ( true )
129
217
} else if ( spSuccess && initialAppIds . length > 0 && permissionsImported == false ) {
130
218
var newApps = [ ]
131
219
initialAppIds ?. map ( ( appId ) => {
@@ -523,6 +611,29 @@ const CippAppPermissionBuilder = ({ onSubmit, currentPermissions = {}, isSubmitt
523
611
< FontAwesomeIcon icon = "rotate-left" />
524
612
</ CButton >
525
613
</ CTooltip >
614
+ < CTooltip content = "Download Manifest" >
615
+ < CButton
616
+ onClick = { ( ) => {
617
+ generateManifest ( )
618
+ } }
619
+ className = { `circular-button` }
620
+ title = { '+' }
621
+ >
622
+ < FontAwesomeIcon icon = "download" />
623
+ </ CButton >
624
+ </ CTooltip >
625
+
626
+ < CTooltip content = "Import Manifest" >
627
+ < CButton
628
+ onClick = { ( ) => {
629
+ importManifest ( )
630
+ } }
631
+ className = { `circular-button` }
632
+ title = { '+' }
633
+ >
634
+ < FontAwesomeIcon icon = "upload" />
635
+ </ CButton >
636
+ </ CTooltip >
526
637
</ CCol >
527
638
</ CRow >
528
639
0 commit comments