-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.sh
32 lines (23 loc) · 1.25 KB
/
auth.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
#!/bin/bash
URL="ha101-1.overkiz.com"
API="https://$URL/enduser-mobile-web/enduserAPI"
# Prompt the user to enter a userId
read -p "Enter userId: " userId
# Prompt the user to enter a userPassword without displaying it on the screen
read -s -p "Enter userPassword: " userPassword
# Prompt the user to enter a PIN
read -p "Enter PIN: " pin
# Prompt the user to enter a label to be user for the token
read -p "Enter token label: " tokenLabel
# Make a POST request to the login URL with the userId and userPassword passed as form URL encoded data
# and save the cookies that are returned
cookies=$(curl -s -c - -d "userId=$userId" -d "userPassword=$userPassword" -X POST "$API/login")
# Make a GET request to the generate tokens URL with the PIN as a parameter and the cookies sent
# Save the "token" field from the response
token=$(curl -s -b "$cookies" "$API/config/$pin/local/tokens/generate" | jq -r '.token')
# Make a POST request to the tokens URL with the PIN as a parameter, the cookies sent and the token as a JSON body
curl -s -b "$cookies" -H "Content-Type: application/json" \
-d '{"label": "'"$tokenLabel"'", "token": "'"$token"'", "scope": "devmode"}' \
-X POST "$API/config/$pin/local/tokens"
# Display the token to the user
echo "Your token: $token