-
Notifications
You must be signed in to change notification settings - Fork 0
/
okta_group_report.py
55 lines (45 loc) · 1.75 KB
/
okta_group_report.py
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
#!/usr/bin/python
#
# The purpose of this script is to be able to generate a report from an Okta group.
# This script will perform as follows:
# 1. Request a group name from the end user
# 2. Return a list of group Ids that match the group name
# 3. Return a CSV from the group ID that is entered by the user name
# This will create an "okta_group_members.csv" file.
#
# Rory Aptekar
# 08.01.19
#
# Updated for Python3+ 2020.09.2
#
import json
import pprint
import csv
import requests
import sys
token = '{api_token}'
base_url = 'https://{subdomain}.okta.com/api/v1/'
headers = {'Authorization' : 'SSWS ' + token,
'Accept' : 'application/json',
'Content-Type' : 'application/json' }
group_search_text = raw_input("Enter the name of the group to find the group_id: ")
url = base_url + 'groups?q=' + group_search_text
req = requests.get(url, headers=headers)
json_obj = req.json()
for json_row in json_obj:
group_id = json_row["id"]
group_name = json_row["profile"]["name"]
print ("Group Name: " + group_name)
print ("Group ID: " + group_id)
group_selected_id = raw_input("Enter the group id to process for user profile updates: ")
url2 = base_url + 'groups/' + group_selected_id + '/users'
req2 = requests.get(url2, headers=headers)
json_obj2 = req2.json()
with open('okta_group_members.csv', 'w') as csvfile:
filewriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
filewriter.writerow(['Full Name','Email Address', 'Status'])
for json_row in json_obj2:
fullName = json_row["profile"]["firstName"] + " " + json_row["profile"]["lastName"]
emailAddress = json_row["profile"]["login"]
status = json_row["status"]
filewriter.writerow([fullName, emailAddress, status])