-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathAccessAuditLogAPI.ps1
75 lines (71 loc) · 3.15 KB
/
AccessAuditLogAPI.ps1
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
#Forces the use of TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
##Declares Variables for the Date Filter for Audit Logs##
$date1 = Get-Date -Date "01/01/1970"
$date2 = (Get-Date).adddays(-7)
$date3 = (Get-Date)
$timespan = (New-TimeSpan -Start $date1 -End $date2).TotalMilliSeconds
$timespan2 = (New-TimeSpan -Start $date1 -End $date3).TotalMilliSeconds
##Declares the Variables for the Filter itself
$fromMillis = [math]::Floor($timespan)
$toMillis = [math]::Floor($timespan2)
##Specify your Access Hostname
$AccessURL = ''
##Specify your oAuth Client ID and Secret
$ClientId = ''
$ClientSecret = ''
$text = "${ClientId}:${ClientSecret}"
$base64 = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($text))
$headers = @{
"Authorization"="Basic $base64";
"Content-Type"="application/x-www-form-urlencoded";
}
##Auth and Get your Bearer Token##
$results = Invoke-WebRequest -Uri "https://$AccessURL/SAAS/auth/oauthtoken?grant_type=client_credentials" -Method POST -Headers $headers
$accessToken = ($results.Content | ConvertFrom-Json).access_token
$authHeader = @{
"Authorization"="Bearer $accessToken";
}
$global:workspaceOneAccessConnection = new-object PSObject -Property @{
'Server' = "https://$AccessURL"
'headers' = $authHeader
}
$global:workspaceOneAccessConnection
##Declare the Header for your Audit Log Query##
$Headers = @{
"x-tenant-id"=""
"Authorization"=$global:workspaceOneAccessConnection.headers.Authorization;
}
$global:workspaceOneAccessConnection
$Headers = @{
"x-tenant-id"=""
"Authorization"=$global:workspaceOneAccessConnection.headers.Authorization;
}
##Perform Audit Search
$Response = Invoke-RestMethod -Uri "https://$AccessURL/analytics/reports/audit?objectType=RuleSet&fromMillis=$fromMillis&toMillis=$toMillis" -Method GET -headers $Headers
$list = New-Object System.Collections.ArrayList
for ($i=0; $i -lt $response.data.length; $i++)
{$list.Add(($response.data[$i][4] | ConvertFrom-Json))}
##Capture AuthMethods into Array and Re-write Audit Log##
$authmethods = Invoke-RestMethod -Uri "https://$AccessURL/SAAS/jersey/manager/api/authmethods" -Method GET -Headers $headers
$authmethods = $authmethods.items | Select-Object authMethodName, uuid
$authnmethods=Get-Content -Path C:\temp\internalauthmethodlist.json | ConvertFrom-Json
for ($i=0; $i -lt $response.data.length; $i++)
{ $list.Add(($response.data[$i][4] | ConvertFrom-Json))| out-null
}
foreach ($item in $list){
foreach ($authmethod in $authnmethods.Methods) {
$item.values = $item.values -replace $authmethod.ID, $authmethod.Name
if ($item.psobject.Properties.name -contains "oldValues") {
$item.oldValues = $item.oldValues -replace $authmethod.ID, $authmethod.Name}
}
}
foreach ($item in $list){
foreach ($authmethod in $authmethods) {
$item.values = $item.values -replace $authmethod.uuid, $authmethod.authMethodName
if ($item.PSObject.Properties.name -contains "oldValues") {
$item.oldValues = $item.oldValues -replace $authmethod.uuid, $authmethod.authMethodName
}
}
}
$List | Export-CSV "C:\temp\auditlog.csv"