-
Notifications
You must be signed in to change notification settings - Fork 2
/
import_sha1.py
53 lines (45 loc) · 1.21 KB
/
import_sha1.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
"""Import a user with unsalted sha1 hash into Okta."""
import hashlib
import base64
import requests
from dotenv import load_dotenv
import os
username = '[email protected]'
password = 'P@ssword123'
sha1 = hashlib.sha1(password.encode()).digest()
b64_sha1 = base64.b64encode(sha1).decode()
print('b64_sha1:', b64_sha1)
load_dotenv()
# Store these in a local .env file.
url = os.getenv('OKTA_ORG_URL')
token = os.getenv('OKTA_API_TOKEN')
headers = {
'Authorization': f'SSWS {token}',
'Accept': 'application/json'
}
user = {
'profile': {
'firstName': 'Isaac',
'lastName': 'Brock',
'email': username,
'login': username
},
'credentials': {
'password': {
'hash': {
'algorithm': 'SHA-1',
'value': b64_sha1
}
}
}
}
# Create the user.
response = requests.post(f'{url}/api/v1/users', json=user, headers=headers)
print(response.json())
# Now, sign in as the user to verify the password hash was imported correctly.
response = requests.post(f'{url}/api/v1/authn', json={'username': username, 'password': password})
authn = response.json()
if response.ok:
print(authn['status'])
else:
print(authn['errorSummary'])