Skip to content

Instantly share code, notes, and snippets.

@heyseus1
Last active November 22, 2019 23:53
Show Gist options
  • Save heyseus1/d8d201a56e3ac01f909a9b80aaa622a4 to your computer and use it in GitHub Desktop.
Save heyseus1/d8d201a56e3ac01f909a9b80aaa622a4 to your computer and use it in GitHub Desktop.
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.put(url,
headers={'Accept': '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:
#print(row['id'], row['email'])
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')
#okta_emails = list(userid.values())
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