-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_local_file_from_okta_attributes.sh
executable file
·75 lines (66 loc) · 2.28 KB
/
create_local_file_from_okta_attributes.sh
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# Configuration
OKTA_DOMAIN="https://your-okta-domain.okta.com"
API_TOKEN="your-okta-api-token"
# Function to fetch user information
get_user_info() {
local username="$1"
curl -s -X GET \
-H "Authorization: SSWS $API_TOKEN" \
-H "Accept: application/json" \
"$OKTA_DOMAIN/api/v1/users/${username}"
}
# Function to create a plist file
create_plist() {
local user_data="$1"
local plist_filename="$2"
# Extract relevant fields from the JSON response
local name=$(echo "$user_data" | jq -r '.profile.displayName // (.profile.firstName + " " + .profile.lastName)')
local email=$(echo "$user_data" | jq -r '.profile.email')
local login=$(echo "$user_data" | jq -r '.profile.login')
local department=$(echo "$user_data" | jq -r '.profile.department // ""')
local title=$(echo "$user_data" | jq -r '.profile.title // ""')
local mobilePhone=$(echo "$user_data" | jq -r '.profile.mobilePhone // ""')
local city=$(echo "$user_data" | jq -r '.profile.city // ""')
local state=$(echo "$user_data" | jq -r '.profile.state // ""')
local zipCode=$(echo "$user_data" | jq -r '.profile.zipCode // ""')
# Create a plist file with the extracted data
cat <<EOF > "$plist_filename"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Name</key>
<string>$name</string>
<key>Email</key>
<string>$email</string>
<key>Login</key>
<string>$login</string>
<key>Department</key>
<string>$department</string>
<key>Title</key>
<string>$title</string>
<key>MobilePhone</key>
<string>$mobilePhone</string>
<key>City</key>
<string>$city</string>
<key>State</key>
<string>$state</string>
<key>ZipCode</key>
<string>$zipCode</string>
</dict>
</plist>
EOF
echo "Plist file '$plist_filename' created successfully."
}
# Main script
read -p "Enter the Okta ID: " username
# Fetch user info from Okta
user_info=$(get_user_info "$username")
# Check if the user was found and generate plist
if echo "$user_info" | jq -e '.id' &>/dev/null; then
plist_filename="$(echo "$user_info" | jq -r '.profile.login').plist"
create_plist "$user_info" "$plist_filename"
else
echo "User not found or an error occurred."
fi