Skip to content

Commit 33742f1

Browse files
committed
update monkey365 core
1 parent bc4d2de commit 33742f1

File tree

90 files changed

+3858
-2185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+3858
-2185
lines changed

core/analysis/Invoke-AzureScanner.ps1

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,5 @@ Function Invoke-AzureScanner{
135135
Catch{
136136
Write-Error $_
137137
}
138-
Finally{
139-
#Perform garbage collection
140-
[System.GC]::GetTotalMemory($true) | out-null
141-
}
142138
}
143139

core/analysis/Invoke-AzureADScanner.ps1 renamed to core/analysis/Invoke-EntraIDScanner.ps1

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,5 @@ Function Invoke-EntraIDScanner{
7373
Catch{
7474
Write-Error $_
7575
}
76-
Finally{
77-
#Perform garbage collection
78-
[gc]::Collect()
79-
}
8076
}
8177

core/analysis/Invoke-M365Scanner.ps1

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,5 @@ Function Invoke-M365Scanner{
8585
Catch{
8686
Write-Error $_
8787
}
88-
Finally{
89-
#Perform garbage collection
90-
[gc]::Collect()
91-
}
9288
}
9389

core/api/auth/Connect-MonkeyCloud.ps1

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,44 @@ Function Connect-MonkeyCloud{
194194
}
195195
#Get licensing information
196196
$O365Object.Licensing = Get-MonkeySKUInfo
197+
#Check If current identity can request users and groups from Microsoft Graph
198+
$p = @{
199+
InformationAction = $O365Object.InformationAction;
200+
Verbose = $O365Object.verbose;
201+
Debug = $O365Object.Debug;
202+
}
203+
$O365Object.canRequestUsersFromMsGraph = Test-CanRequestUser @p
204+
$O365Object.canRequestGroupsFromMsGraph = Test-CanRequestGroup @p
205+
#Get information about current identity
206+
$O365Object.me = Get-MonkeyMe @p
207+
#Check If connected to Azure AD
208+
If($O365Object.canRequestUsersFromMsGraph -eq $false -and $null -eq $O365Object.Tenant.CompanyInfo){
209+
$msg = @{
210+
MessageData = ($message.NotConnectedTo -f "Microsoft Entra ID");
211+
callStack = (Get-PSCallStack | Select-Object -First 1);
212+
logLevel = 'warning';
213+
InformationAction = $O365Object.InformationAction;
214+
Tags = @('Monkey365GraphAPIError');
215+
}
216+
Write-Warning @msg
217+
$O365Object.onlineServices.EntraID = $false
218+
}
219+
Else{
220+
$O365Object.onlineServices.EntraID = $true
221+
}
197222
#Get actual userId
198-
$authObject = $O365Object.auth_tokens.GetEnumerator() | Where-Object {$null -ne $_.Value} | Select-Object -ExpandProperty Value -First 1
199-
If($null -ne $authObject){
200-
$O365Object.userId = $authObject | Get-UserIdFromToken
223+
If($O365Object.isConfidentialApp){
224+
$O365Object.userId = $O365Object.me.id;
225+
}
226+
Else{
227+
$authObject = $O365Object.auth_tokens.GetEnumerator() | Where-Object {$null -ne $_.Value} | Select-Object -ExpandProperty Value -First 1
228+
If($null -ne $authObject){
229+
$O365Object.userId = $authObject | Get-UserIdFromToken
230+
}
201231
}
202232
#Get Azure AD permissions
203233
If($O365Object.isConfidentialApp){
204-
$app_Permissions = Get-MonkeyMSGraphObjectDirectoryRole -ObjectId $O365Object.clientApplicationId -ObjectType servicePrincipal
234+
$app_Permissions = Get-MonkeyMSGraphObjectDirectoryRole -ObjectId $O365Object.me.id -ObjectType servicePrincipal
205235
If($app_Permissions){
206236
$O365Object.aadPermissions = $app_Permissions
207237
}
@@ -236,7 +266,9 @@ Function Connect-MonkeyCloud{
236266
}
237267
#Check If requestMFA for users must be enabled by config
238268
try{
239-
$requestMFA = $O365Object.internal_config.entraId.forceRequestMFA
269+
$out = $null;
270+
[void][bool]::TryParse($O365Object.internal_config.entraId.forceRequestMFA, [ref]$out);
271+
$requestMFA = $out;
240272
}
241273
catch{
242274
$msg = @{
@@ -253,31 +285,6 @@ Function Connect-MonkeyCloud{
253285
#Force request MFA for users
254286
$O365Object.canRequestMFAForUsers = $true;
255287
}
256-
#Check If current identity can request users and groups from Microsoft Graph
257-
$p = @{
258-
InformationAction = $O365Object.InformationAction;
259-
Verbose = $O365Object.verbose;
260-
Debug = $O365Object.Debug;
261-
}
262-
$O365Object.canRequestUsersFromMsGraph = Test-CanRequestUser @p
263-
$O365Object.canRequestGroupsFromMsGraph = Test-CanRequestGroup @p
264-
#Get information about current identity
265-
$O365Object.me = Get-MonkeyMe @p
266-
#Check If connected to Azure AD
267-
If($O365Object.canRequestUsersFromMsGraph -eq $false -and $null -eq $O365Object.Tenant.CompanyInfo){
268-
$msg = @{
269-
MessageData = ($message.NotConnectedTo -f "Microsoft Entra ID");
270-
callStack = (Get-PSCallStack | Select-Object -First 1);
271-
logLevel = 'warning';
272-
InformationAction = $O365Object.InformationAction;
273-
Tags = @('Monkey365GraphAPIError');
274-
}
275-
Write-Warning @msg
276-
$O365Object.onlineServices.EntraID = $false
277-
}
278-
Else{
279-
$O365Object.onlineServices.EntraID = $true
280-
}
281288
#Check If EntraID P2 is enabled
282289
If($null -ne $O365Object.Tenant.licensing -and $null -ne $O365Object.Tenant.licensing.EntraIDP2){
283290
$msg = @{

core/api/auth/generic/Connect-MonkeyGenericApplication.ps1

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,40 @@ Function Connect-MonkeyGenericApplication {
4242
[Parameter(Mandatory=$true, HelpMessage="Resource to connect")]
4343
[String]$Resource,
4444

45+
[Parameter(Mandatory=$false, HelpMessage="MSAL Client Application")]
46+
[Object]$Application,
47+
4548
[Parameter(Mandatory=$false, HelpMessage="Redirect URI")]
4649
[String]$RedirectUri
4750
)
4851
Begin{
4952
#Set new params
5053
$new_params = @{}
51-
foreach ($param in $O365Object.msal_application_args.GetEnumerator()){
54+
ForEach ($param in $O365Object.msal_application_args.GetEnumerator()){
5255
$new_params.add($param.Key, $param.Value)
5356
}
5457
}
5558
Process{
56-
if($O365Object.isConfidentialApp -eq $false){
59+
If($O365Object.isConfidentialApp -eq $false){
60+
#Check if passed application
61+
If($PSBoundParameters.ContainsKey('Application') -and $PSBoundParameters['Application']){
62+
If($PSBoundParameters['Application'] -is [Microsoft.Identity.Client.PublicClientApplication]){
63+
$new_params.publicApp = $PSBoundParameters['Application']
64+
}
65+
Else{
66+
$msg = @{
67+
MessageData = "Unable to get access token. Application is not a public client application";
68+
callStack = (Get-PSCallStack | Select-Object -First 1);
69+
logLevel = 'Warning';
70+
InformationAction = $O365Object.InformationAction;
71+
Tags = @('MonkeyGenericApplicationClientIdError');
72+
}
73+
Write-Warning @msg
74+
return
75+
}
76+
}
5777
#Check if application is present
58-
if(($O365Object.msal_public_applications.Where({$_.ClientId -eq (Get-WellKnownAzureService -AzureService ("{0}" -f $AzureService))})).Count -gt 0){
78+
ElseIf(($O365Object.msal_public_applications.Where({$_.ClientId -eq (Get-WellKnownAzureService -AzureService ("{0}" -f $AzureService))})).Count -gt 0){
5979
$new_params.publicApp = $O365Object.msal_public_applications.Where({$_.ClientId -eq (Get-WellKnownAzureService -AzureService ("{0}" -f $AzureService))}) | Select-Object -First 1
6080
#Add silent
6181
if(-NOT $new_params.ContainsKey('Silent')){
@@ -122,10 +142,28 @@ Function Connect-MonkeyGenericApplication {
122142
}
123143
}
124144
#Add redirect URI if present
125-
if($PSBoundParameters.ContainsKey('RedirectUri') -and $PSBoundParameters['RedirectUri']){
145+
If($PSBoundParameters.ContainsKey('RedirectUri') -and $PSBoundParameters['RedirectUri']){
126146
$new_params.publicApp.RedirectUri = $PSBoundParameters['RedirectUri'];
127147
}
128148
}
149+
Else{
150+
If($PSBoundParameters.ContainsKey('Application') -and $PSBoundParameters['Application']){
151+
If($PSBoundParameters['Application'] -is [Microsoft.Identity.Client.ConfidentialClientApplication]){
152+
$new_params.confidentialApp = $PSBoundParameters['Application']
153+
}
154+
Else{
155+
$msg = @{
156+
MessageData = "Unable to get access token. Application is not a confidential client application";
157+
callStack = (Get-PSCallStack | Select-Object -First 1);
158+
logLevel = 'Warning';
159+
InformationAction = $O365Object.InformationAction;
160+
Tags = @('MonkeyGenericApplicationClientIdError');
161+
}
162+
Write-Warning @msg
163+
return
164+
}
165+
}
166+
}
129167
#Add resource to param
130168
[void]$new_params.add('Resource', $Resource)
131169
#Try to get token

core/api/auth/microsoft365/Connect-MonkeyM365.ps1

Lines changed: 97 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,55 @@ Function Connect-MonkeyM365{
454454
}
455455
Write-Information @msg
456456
#Connect to Fabric
457-
$p = @{
458-
Resource = $O365Object.Environment.Fabric;
459-
AzureService = "AzurePowershell";
460-
InformationAction = $O365Object.InformationAction;
461-
Verbose = $O365Object.verbose;
462-
Debug = $O365Object.debug;
457+
If($O365Object.isConfidentialApp){
458+
If($O365Object.initParams.GetEnumerator().Where({$_.Key -eq 'PowerBIClientId'}).Count -gt 0){
459+
$application = $O365Object.msal_confidential_applications.Where({$_.ClientId -eq $O365Object.initParams.Item('PowerBIClientId')}) | Select-Object -First 1 -ErrorAction Ignore
460+
If($application){
461+
$p = @{
462+
Resource = $O365Object.Environment.Fabric;
463+
Application = $application;
464+
InformationAction = $O365Object.InformationAction;
465+
Verbose = $O365Object.verbose;
466+
Debug = $O365Object.debug;
467+
}
468+
#Connect to Microsoft Fabric
469+
$O365Object.auth_tokens.Fabric = Connect-MonkeyGenericApplication @p
470+
}
471+
Else{
472+
$msg = @{
473+
MessageData = "Unable to connect to Microsoft Fabric. Confidential application was not found";
474+
callStack = (Get-PSCallStack | Select-Object -First 1);
475+
logLevel = 'warning';
476+
InformationAction = $O365Object.InformationAction;
477+
Tags = @('Monkey365FabricError');
478+
}
479+
Write-Warning @msg
480+
return
481+
}
482+
}
483+
Else{
484+
$msg = @{
485+
MessageData = "Unable to connect to Microsoft Fabric. Confidential application was not found";
486+
callStack = (Get-PSCallStack | Select-Object -First 1);
487+
logLevel = 'warning';
488+
InformationAction = $O365Object.InformationAction;
489+
Tags = @('Monkey365FabricError');
490+
}
491+
Write-Warning @msg
492+
return
493+
}
494+
}
495+
Else{
496+
$p = @{
497+
Resource = $O365Object.Environment.Fabric;
498+
AzureService = "AzurePowershell";
499+
InformationAction = $O365Object.InformationAction;
500+
Verbose = $O365Object.verbose;
501+
Debug = $O365Object.debug;
502+
}
503+
#Connect to Microsoft Fabric
504+
$O365Object.auth_tokens.Fabric = Connect-MonkeyGenericApplication @p
463505
}
464-
$O365Object.auth_tokens.Fabric = Connect-MonkeyGenericApplication @p
465506
If($null -ne $O365Object.auth_tokens.Fabric){
466507
$O365Object.onlineServices.Item('PowerBI') = $true
467508
}
@@ -471,7 +512,7 @@ Function Connect-MonkeyM365{
471512
callStack = (Get-PSCallStack | Select-Object -First 1);
472513
logLevel = 'warning';
473514
InformationAction = $O365Object.InformationAction;
474-
Tags = @('Monkey365TeamsError');
515+
Tags = @('Monkey365FabricError');
475516
}
476517
Write-Warning @msg
477518
}
@@ -484,15 +525,55 @@ Function Connect-MonkeyM365{
484525
Tags = @('TokenRequestInfoMessage');
485526
}
486527
Write-Information @msg
487-
#Connect to PowerBI
488-
$p = @{
489-
Resource = $O365Object.Environment.PowerBI;
490-
AzureService = "AzurePowershell";
491-
InformationAction = $O365Object.InformationAction;
492-
Verbose = $O365Object.verbose;
493-
Debug = $O365Object.debug;
528+
If($O365Object.isConfidentialApp){
529+
If($O365Object.initParams.GetEnumerator().Where({$_.Key -eq 'PowerBIClientId'}).Count -gt 0){
530+
$application = $O365Object.msal_confidential_applications.Where({$_.ClientId -eq $O365Object.initParams.Item('PowerBIClientId')}) | Select-Object -First 1 -ErrorAction Ignore
531+
If($application){
532+
$p = @{
533+
Resource = $O365Object.Environment.PowerBI;
534+
Application = $application;
535+
InformationAction = $O365Object.InformationAction;
536+
Verbose = $O365Object.verbose;
537+
Debug = $O365Object.debug;
538+
}
539+
#Connect to Microsoft Fabric
540+
$O365Object.auth_tokens.PowerBI = Connect-MonkeyGenericApplication @p
541+
}
542+
Else{
543+
$msg = @{
544+
MessageData = "Unable to connect to Microsoft PowerBI. Confidential application was not found";
545+
callStack = (Get-PSCallStack | Select-Object -First 1);
546+
logLevel = 'warning';
547+
InformationAction = $O365Object.InformationAction;
548+
Tags = @('Monkey365FabricError');
549+
}
550+
Write-Warning @msg
551+
return
552+
}
553+
}
554+
Else{
555+
$msg = @{
556+
MessageData = "Unable to connect to Microsoft PowerBI. Confidential application was not found";
557+
callStack = (Get-PSCallStack | Select-Object -First 1);
558+
logLevel = 'warning';
559+
InformationAction = $O365Object.InformationAction;
560+
Tags = @('Monkey365FabricError');
561+
}
562+
Write-Warning @msg
563+
return
564+
}
565+
}
566+
Else{
567+
#Connect to PowerBI
568+
$p = @{
569+
Resource = $O365Object.Environment.PowerBI;
570+
AzureService = "AzurePowershell";
571+
InformationAction = $O365Object.InformationAction;
572+
Verbose = $O365Object.verbose;
573+
Debug = $O365Object.debug;
574+
}
575+
$O365Object.auth_tokens.PowerBI = Connect-MonkeyGenericApplication @p
494576
}
495-
$O365Object.auth_tokens.PowerBI = Connect-MonkeyGenericApplication @p
496577
If($null -ne $O365Object.auth_tokens.PowerBI){
497578
#Get Backend URI
498579
$O365Object.PowerBIBackendUri = Get-MonkeyPowerBIBackend

0 commit comments

Comments
 (0)