Last active
September 23, 2016 10:04
-
-
Save shauns/9a110c02d900dfe72ec3030f0fd2d98e to your computer and use it in GitHub Desktop.
Use management API to create an Auth0 user
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 | |
# Needs create:users scope, https://auth0.com/docs/api/management/v2#!/Users/post_users | |
headers = {'Authorization': 'Bearer qwertyuiop'} | |
body = {'connection': 'Username-Password-Authentication', 'email': u'[email protected]', 'family_name': 'Bloggs', 'given_name': 'Joe', 'password': 'secrets'} | |
res = requests.post('https://freeformers.auth0.com/api/v2/users', json=body, headers=headers) | |
res.json() | |
import unicodecsv | |
r = unicodecsv.DictReader(open('filename.csv')) | |
lines = [] | |
while True: | |
try: | |
lines.append(r.next()) | |
except StopIteration: | |
break | |
handled_usernames = set() | |
for line in lines: | |
if line['username'] in handled_usernames: | |
continue | |
print line['username'] | |
body = {'connection': 'Username-Password-Authentication', 'email': line['email'], 'family_name': line['family_name'], 'given_name': line['given_name'], 'password': 'secret'} | |
res = requests.post('https://freeformers.auth0.com/api/v2/users', json=body, headers=headers) | |
res.raise_for_status() | |
handled_usernames.add(line['username']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment