forked from thrnz/docker-wireguard-pia
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpia-auth.sh
54 lines (48 loc) · 1.15 KB
/
pia-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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
# Generate and output a PIA auth token
#
# Requires jq and curl
#
# Options:
# -u <username>
# -p <password>
#
# Example:
# pia-auth.sh -u p0000000 -p mypassword > ~/.pia-token
#
# deauth using:
# curl --silent --show-error --request POST \
# --header "Content-Type: application/json" \
# --header "Authorization: Token $(cat ~/.pia-token)" \
# --data "{}" \
# "https://www.privateinternetaccess.com/api/client/v2/expire_token"
while getopts ":u:p:" args; do
case ${args} in
u)
user=$OPTARG
;;
p)
pass=$OPTARG
;;
esac
done
usage() {
echo "Options:"
echo " -u <username>"
echo " -p <password>"
exit 1
}
get_auth_token () {
TOK=$(curl --silent --show-error --request POST --max-time $curl_max_time \
--header "Content-Type: application/json" \
--data "{\"username\":\"$user\",\"password\":\"$pass\"}" \
"https://www.privateinternetaccess.com/api/client/v2/token" | jq -r '.token')
[ $? -ne 0 ] && echo "Failed to acquire new auth token" && exit 1
echo "$TOK"
}
if [ -z "$pass" ] || [ -z "$user" ]; then
usage
fi
curl_max_time=15
get_auth_token
exit 0