Skip to content

Commit b7db5d2

Browse files
committed
Update authentication objects and functions
1 parent c2b0238 commit b7db5d2

5 files changed

Lines changed: 113 additions & 68 deletions

File tree

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Monkey365 - the PowerShell Cloud Security Tool for Azure and Microsoft 365 (copyright 2022) by Juan Garrido
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
Function Connect-MonkeyAIPService{
16+
<#
17+
.SYNOPSIS
18+
Function to connect to Azure Information Protection
19+
20+
.DESCRIPTION
21+
Function to connect to Azure Information Protection
22+
23+
.INPUTS
24+
25+
.OUTPUTS
26+
27+
.EXAMPLE
28+
29+
.NOTES
30+
Author : Juan Garrido
31+
Twitter : @tr1ana
32+
File Name : Connect-MonkeyAIPService
33+
Version : 1.0
34+
35+
.LINK
36+
https://github.com/silverhack/monkey365
37+
#>
38+
[CmdletBinding()]
39+
Param ()
40+
Process{
41+
Try{
42+
If($null -eq $O365Object.auth_tokens.AADRM){
43+
$msg = @{
44+
MessageData = ($message.TokenRequestInfoMessage -f "Microsoft Azure Information Protection")
45+
callStack = (Get-PSCallStack | Select-Object -First 1);
46+
logLevel = 'info';
47+
InformationAction = $O365Object.InformationAction;
48+
Tags = @('AIPTokenRequestInfoMessage');
49+
}
50+
Write-Information @msg
51+
#Set RedirectUri
52+
If($O365Object.cloudEnvironment -eq [Microsoft.Identity.Client.AzureCloudInstance]::AzureUsGovernment){
53+
$redirectUri = "https://aadrm.us/adminpowershell"
54+
}
55+
Else{
56+
$redirectUri = "https://aadrm.com/adminpowershell"
57+
}
58+
#Connect to Azure Information Protection
59+
$p = @{
60+
Resource = $O365Object.Environment.AADRM;
61+
AzureService = "AzurePowershell";
62+
RedirectUri = $redirectUri;
63+
InformationAction = $O365Object.InformationAction;
64+
Verbose = $O365Object.verbose;
65+
Debug = $O365Object.debug;
66+
}
67+
$O365Object.auth_tokens.AADRM = Connect-MonkeyGenericApplication @p
68+
If($null -ne $O365Object.auth_tokens.AADRM){
69+
#Get Service locator url
70+
$service_locator = Get-AADRMServiceLocatorUrl
71+
If($null -ne $service_locator){
72+
#set internal object
73+
If($O365Object.Environment.ContainsKey('aadrm_service_locator')){
74+
$O365Object.Environment.aadrm_service_locator = $service_locator;
75+
}
76+
Else{
77+
$O365Object.Environment.Add('aadrm_service_locator',$service_locator)
78+
}
79+
$O365Object.onlineServices.Item($service) = $true
80+
}
81+
}
82+
}
83+
}
84+
Catch{
85+
$msg = @{
86+
Message = $_;
87+
callStack = (Get-PSCallStack | Select-Object -First 1);
88+
logLevel = 'error';
89+
Tags = @('AIPAuthenticationError');
90+
}
91+
Write-Error @msg
92+
}
93+
}
94+
}

core/api/auth/azure/Connect-MonkeyAzure.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,4 @@ Function Connect-MonkeyAzure{
118118
}
119119
}
120120
}
121-
}
122-
121+
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ Function Connect-MonkeyGenericApplication {
7575
foreach ($param in $O365Object.application_args.GetEnumerator()){
7676
$client_app.add($param.Key, $param.Value)
7777
}
78+
#Add RedirectURI
79+
If($PSBoundParameters.ContainsKey('RedirectUri') -and $PSBoundParameters['RedirectUri']){
80+
If($client_app.ContainsKey('RedirectUri')){
81+
$client_app.RedirectUri = $PSBoundParameters['RedirectUri']
82+
}
83+
Else{
84+
$client_app.add('RedirectUri', $PSBoundParameters['RedirectUri'])
85+
}
86+
}
7887
#Get ClientId from Microsoft Graph
7988
$clientId = Get-WellKnownAzureService -AzureService $AzureService
8089
if($clientId){

core/api/auth/intune/Connect-MonkeyIntune.ps1

Lines changed: 0 additions & 43 deletions
This file was deleted.

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

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ Function Connect-MonkeyM365{
6060
$moduleFile = Get-PSExoModuleFile @p
6161
If($moduleFile){
6262
$O365Object.onlineServices.Item($service) = $true
63+
#Connect AIPService
64+
Connect-MonkeyAIPService
65+
Start-Sleep -Milliseconds 100
6366
}
6467
Else{
6568
$msg = @{
@@ -102,6 +105,9 @@ Function Connect-MonkeyM365{
102105
$moduleFile = Get-PSExoModuleFile @p
103106
If($moduleFile){
104107
$O365Object.onlineServices.Item($service) = $true
108+
#Connect AIPService
109+
Connect-MonkeyAIPService
110+
Start-Sleep -Milliseconds 100
105111
}
106112
Else{
107113
$msg = @{
@@ -263,6 +269,9 @@ Function Connect-MonkeyM365{
263269
#Check If connected to SharePoint
264270
If($O365Object.isSharePointAdministrator -or $null -ne $O365Object.spoSites){
265271
$O365Object.onlineServices.Item($service) = $true
272+
#Connect AIPService
273+
Connect-MonkeyAIPService
274+
Start-Sleep -Milliseconds 100
266275
}
267276
}
268277
}
@@ -502,29 +511,6 @@ Function Connect-MonkeyM365{
502511
}
503512
}
504513
}
505-
#Connect to Microsoft Intune
506-
'intune'{
507-
$msg = @{
508-
MessageData = ($message.TokenRequestInfoMessage -f "Microsoft Intune")
509-
callStack = (Get-PSCallStack | Select-Object -First 1);
510-
logLevel = 'info';
511-
InformationAction = $O365Object.InformationAction;
512-
Tags = @('TokenRequestInfoMessage');
513-
}
514-
Write-Information @msg
515-
$p = @{
516-
Resource = $O365Object.Environment.Graphv2;
517-
AzureService = "Intune";
518-
InformationAction = $O365Object.InformationAction;
519-
Verbose = $O365Object.verbose;
520-
Debug = $O365Object.debug;
521-
}
522-
$O365Object.auth_tokens.Intune = Connect-MonkeyGenericApplication @p
523-
#$O365Object.auth_tokens.Intune = Connect-MonkeyIntune
524-
If($null -ne $O365Object.auth_tokens.Intune){
525-
$O365Object.onlineServices.Item($service) = $true
526-
}
527-
}
528514
}
529515
}
530516
}

0 commit comments

Comments
 (0)