Created
November 22, 2019 23:55
-
-
Save heyseus1/f7425cdf70b561ce6751b8127c133c4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import csv | |
import os | |
# in order to run this script you will need an environmental variable set in your bash_profile called OKTA_AUTH that equals an Okta API Key. | |
# Specify your Group ID (you can get this id by running the curl command below) | |
# curl -v -X GET -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: 'API KEY GOES HERE'" "https://{domain-here}.okta.com/api/v1/groups?limit=200" | |
# might want to install jq on your terminal to format the JSON | |
key = os.environ['OKTA_AUTH'] | |
groupid = input('enter groupid:') | |
api_url = "https://login.therealreal.com/api/v1/groups/{}/users/{}" | |
# authorize Okta and input id data to add users in a group | |
def auth_okta(id): | |
url = api_url.format(groupid, id) | |
print(url) | |
return requests.delete(url, | |
headers={'content-type': 'application/json', | |
'authorization': key}) | |
# reads your application csv file (be sure to rename your file to app.csv) | |
# if app.csv fails due column name be sure to remove any whitespace! | |
def read_app_csv(File): | |
with open(File, mode='r') as filehandler: | |
reader = csv.DictReader(filehandler) | |
emailholder = [] | |
for row in reader: | |
email = row['email'] | |
emailholder.append(email) | |
return emailholder | |
# reads the Okta csv file should contain an Email and ID (duplicate entries ok they will be parsed) | |
def read_okta_csv(File): | |
with open(File, mode='r') as filehandler: | |
reader = csv.DictReader(filehandler) | |
userid = {} | |
idholder = [] | |
for row in reader: | |
id = row['id'] | |
email = row['email'] | |
if id in idholder: | |
pass | |
else: | |
idholder.append(id) | |
userid[id] = email | |
return userid | |
# main function to compare okta and application data and extract id | |
def main(): | |
appemailholder = read_app_csv('app.csv') | |
userid = read_okta_csv('okta.csv') | |
for id, email in userid.items(): | |
if email in appemailholder: | |
auth_okta(id) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment