Skip to content

Commit 043327e

Browse files
committed
update m365 helpers
1 parent 6bb22de commit 043327e

8 files changed

Lines changed: 59 additions & 10 deletions

File tree

‎core/api/m365/exchangeonline/helpers/Get-PSExoModuleFile.ps1‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,20 @@ Function Get-PSExoModuleFile{
3636
[cmdletbinding()]
3737
Param (
3838
[parameter(Mandatory=$false, HelpMessage="Purview")]
39-
[Switch]$Purview
39+
[Switch]$Purview,
40+
41+
[parameter(Mandatory=$false, HelpMessage="Authentication Object")]
42+
[Object]$Authentication
4043
)
4144
Try{
4245
If($PSBoundParameters['Purview'] -and $PSBoundParameters['Purview'].IsPresent){
4346
#Get Security and Compliance Auth token
44-
$ExoAuth = $O365Object.auth_tokens.ComplianceCenter
47+
If($PSBoundParameters.ContainsKey('Authentication') -and $PSBoundParameters['Authentication']){
48+
$ExoAuth = $PSBoundParameters['Authentication']
49+
}
50+
Else{
51+
$ExoAuth = $O365Object.auth_tokens.ComplianceCenter
52+
}
4553
#Get TenantId from token
4654
#$tid = Read-JWTtoken -token $O365Object.auth_tokens.ComplianceCenter.AccessToken | Select-Object -ExpandProperty tid -ErrorAction Ignore
4755
#Get Backend Uri
@@ -99,7 +107,12 @@ Function Get-PSExoModuleFile{
99107
#Get environment
100108
$Environment = $O365Object.Environment
101109
#Get Auth token
102-
$exoAuth = $O365Object.auth_tokens.ExchangeOnline
110+
If($PSBoundParameters.ContainsKey('Authentication') -and $PSBoundParameters['Authentication']){
111+
$ExoAuth = $PSBoundParameters['Authentication']
112+
}
113+
Else{
114+
$ExoAuth = $O365Object.auth_tokens.ExchangeOnline
115+
}
103116
#Get Module file
104117
$param = @{
105118
Authentication = $exoAuth;

‎core/api/m365/m365adminportal/api/Get-MonkeyM365AdminObject.ps1‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,14 @@ Function Get-MonkeyM365AdminObject{
8181
break
8282
}
8383
#Get Authorization Header
84-
$AuthHeader = $Authentication.CreateAuthorizationHeader()
84+
$methods = $Authentication | Get-Member | Where-Object {$_.MemberType -eq 'Method'} | Select-Object -ExpandProperty Name
85+
#Get Authorization Header
86+
If($null -ne $methods -and $methods.Contains('CreateAuthorizationHeader')){
87+
$AuthHeader = $Authentication.CreateAuthorizationHeader()
88+
}
89+
Else{
90+
$AuthHeader = ("Bearer {0}" -f $Authentication.AccessToken)
91+
}
8592
#Get internal Path
8693
switch ($InternalPath) {
8794
'settings'{$base_uri = 'settings'}

‎core/api/m365/microsoftteams/api/Get-MonkeyTeamsObject.ps1‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,14 @@ Function Get-MonkeyTeamsObject{
101101
'TeamsTenant'{$path = 'Teams.Tenant'}
102102
}
103103
#Get Authorization Header
104-
$AuthHeader = $Authentication.CreateAuthorizationHeader()
104+
$methods = $Authentication | Get-Member | Where-Object {$_.MemberType -eq 'Method'} | Select-Object -ExpandProperty Name
105+
#Get Authorization Header
106+
If($null -ne $methods -and $methods.Contains('CreateAuthorizationHeader')){
107+
$AuthHeader = $Authentication.CreateAuthorizationHeader()
108+
}
109+
Else{
110+
$AuthHeader = ("Bearer {0}" -f $Authentication.AccessToken)
111+
}
105112
#set msgraph uri
106113
$base_uri = ("{0}/{1}" -f $Environment.Teams, $path)
107114
$my_filter = $null

‎core/api/m365/sharepointonline/csom/api/Invoke-MonkeyCSOMDefaultRequest.ps1‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,14 @@ Function Invoke-MonkeyCSOMDefaultRequest{
7171
break
7272
}
7373
#Get Authorization Header
74-
$AuthHeader = ("Bearer {0}" -f $Authentication.AccessToken)
74+
$methods = $Authentication | Get-Member | Where-Object {$_.MemberType -eq 'Method'} | Select-Object -ExpandProperty Name
75+
#Get Authorization Header
76+
If($null -ne $methods -and $methods.Contains('CreateAuthorizationHeader')){
77+
$AuthHeader = $Authentication.CreateAuthorizationHeader()
78+
}
79+
Else{
80+
$AuthHeader = ("Bearer {0}" -f $Authentication.AccessToken)
81+
}
7582
#Set Endpoint
7683
if($Endpoint){
7784
$Server = [System.Uri]::new($Endpoint)

‎core/api/m365/sharepointonline/csom/api/Invoke-MonkeyCSOMRequest.ps1‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,14 @@ Function Invoke-MonkeyCSOMRequest{
7777
break
7878
}
7979
#Get Authorization Header
80-
$AuthHeader = ("Bearer {0}" -f $Authentication.AccessToken)
80+
$methods = $Authentication | Get-Member | Where-Object {$_.MemberType -eq 'Method'} | Select-Object -ExpandProperty Name
81+
#Get Authorization Header
82+
If($null -ne $methods -and $methods.Contains('CreateAuthorizationHeader')){
83+
$AuthHeader = $Authentication.CreateAuthorizationHeader()
84+
}
85+
Else{
86+
$AuthHeader = ("Bearer {0}" -f $Authentication.AccessToken)
87+
}
8188
#Set Endpoint
8289
try{
8390
if($Endpoint){

‎core/api/m365/sharepointonline/csom/helpers/tenant/Get-MonkeyCSOMOffice365Tenant.ps1‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Function Get-MonkeyCSOMOffice365Tenant{
5353
}
5454
#Execute query
5555
$m365_tenant = Invoke-MonkeyCSOMRequest @p
56-
if($m365_tenant){
56+
If($m365_tenant){
5757
#Add url
5858
$m365_tenant | Add-Member -type NoteProperty -name Url -value $O365Object.auth_tokens.SharePointAdminOnline.Resource -Force
5959
return $m365_tenant

‎core/api/m365/sharepointonline/csom/helpers/tenant/Get-MonkeyCSOMTenant.ps1‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Function Get-MonkeyCSOMTenant{
4242
[xml]$body_data = '<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="monkey365" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009"><Actions><ObjectPath Id="334" ObjectPathId="333" /><Query Id="335" ObjectPathId="333"><Query SelectAllProperties="true"><Properties><Property Name="HideDefaultThemes" ScalarProperty="true" /></Properties></Query></Query></Actions><ObjectPaths><Constructor Id="333" TypeId="{268004ae-ef6b-4e9b-8425-127220d84719}" /></ObjectPaths></Request>'
4343
}
4444
Process{
45-
if($null -ne $O365Object.auth_tokens.SharePointAdminOnline){
45+
If($null -ne $O365Object.auth_tokens.SharePointAdminOnline){
4646
$p = @{
4747
Authentication = $O365Object.auth_tokens.SharePointAdminOnline;
4848
Data = $body_data;

‎core/api/m365/sharepointonline/utils/Test-SiteConnection.ps1‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,15 @@ Function Test-SiteConnection{
4848
Write-Warning -Message ($message.NullAuthenticationDetected -f "SharePoint Online Web API")
4949
return
5050
}
51-
$sps_web_auth = $Authentication.CreateAuthorizationHeader()
51+
#Get Authorization Header
52+
$methods = $Authentication | Get-Member | Where-Object {$_.MemberType -eq 'Method'} | Select-Object -ExpandProperty Name
53+
#Get Authorization Header
54+
If($null -ne $methods -and $methods.Contains('CreateAuthorizationHeader')){
55+
$sps_web_auth = $Authentication.CreateAuthorizationHeader()
56+
}
57+
Else{
58+
$sps_web_auth = ("Bearer {0}" -f $Authentication.AccessToken)
59+
}
5260
$headers = @{
5361
Authorization=$sps_web_auth;
5462
}

0 commit comments

Comments
 (0)