Skip to content

Commit 9e8fba1

Browse files
authored
Merge pull request #41797 from MarkusVi/quickfix81
quickfix81
2 parents f59c105 + a05e0bf commit 9e8fba1

File tree

1 file changed

+0
-69
lines changed

1 file changed

+0
-69
lines changed

articles/active-directory/active-directory-reporting-api-audit-samples.md

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -87,75 +87,6 @@ Once you finish editing the script, run it and verify that the expected data fro
8787

8888
The script returns output from the audit report in JSON format. It also creates an `audit.json` file with the same output. You can experiment by modifying the script to return data from other reports, and comment out the output formats that you do not need.
8989

90-
## Bash script
91-
#!/bin/bash
92-
93-
# Author: Ken Hoff ([email protected])
94-
# Date: 2015.08.20
95-
# NOTE: This script requires jq (https://stedolan.github.io/jq/)
96-
97-
CLIENT_ID="your-application-client-id-here" # Should be a ~35 character string insert your info here
98-
CLIENT_SECRET="your-application-client-secret-here" # Should be a ~44 character string insert your info here
99-
LOGIN_URL="https://login.microsoftonline.com"
100-
TENANT_DOMAIN="your-directory-name-here.onmicrosoft.com" # For example, contoso.onmicrosoft.com
101-
102-
TOKEN_INFO=$(curl -s --data-urlencode "grant_type=client_credentials" --data-urlencode "client_id=$CLIENT_ID" --data-urlencode "client_secret=$CLIENT_SECRET" "$LOGIN_URL/$TENANT_DOMAIN/oauth2/token?api-version=1.0")
103-
104-
TOKEN_TYPE=$(echo $TOKEN_INFO | ./jq-win64.exe -r '.token_type')
105-
ACCESS_TOKEN=$(echo $TOKEN_INFO | ./jq-win64.exe -r '.access_token')
106-
107-
# get yesterday's date
108-
109-
YESTERDAY=$(date --date='1 day ago' +'%Y-%m-%d')
110-
111-
URL="https://graph.windows.net/$TENANT_DOMAIN/activities/audit?api-version=beta&$filter=activityDate%20gt%20$YESTERDAY"
112-
113-
114-
REPORT=$(curl -s --header "Authorization: $TOKEN_TYPE $ACCESS_TOKEN" $URL)
115-
116-
echo $REPORT | ./jq-win64.exe -r '.value' | ./jq-win64.exe -r ".[]"
117-
118-
## Python script
119-
# Author: Michael McLaughlin ([email protected])
120-
# Date: January 20, 2016
121-
# This requires the Python Requests module: http://docs.python-requests.org
122-
123-
import requests
124-
import datetime
125-
import sys
126-
127-
client_id = 'your-application-client-id-here'
128-
client_secret = 'your-application-client-secret-here'
129-
login_url = 'https://login.microsoftonline.com/'
130-
tenant_domain = 'your-directory-name-here.onmicrosoft.com'
131-
132-
# Get an OAuth access token
133-
bodyvals = {'client_id': client_id,
134-
'client_secret': client_secret,
135-
'grant_type': 'client_credentials'}
136-
137-
request_url = login_url + tenant_domain + '/oauth2/token?api-version=1.0'
138-
token_response = requests.post(request_url, data=bodyvals)
139-
140-
access_token = token_response.json().get('access_token')
141-
token_type = token_response.json().get('token_type')
142-
143-
if access_token is None or token_type is None:
144-
print "ERROR: Couldn't get access token"
145-
sys.exit(1)
146-
147-
# Use the access token to make the API request
148-
yesterday = datetime.date.strftime(datetime.date.today() - datetime.timedelta(days=1), '%Y-%m-%d')
149-
150-
header_params = {'Authorization': token_type + ' ' + access_token}
151-
request_string = 'https://graph.windows.net/' + tenant_domain + '/activities/audit?api-version=beta&$filter=activityDate%20gt%20' + yesterday
152-
response = requests.get(request_string, headers = header_params)
153-
154-
if response.status_code is 200:
155-
print response.content
156-
else:
157-
print 'ERROR: API request failed'
158-
15990

16091

16192

0 commit comments

Comments
 (0)