-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoken_request.sh
executable file
·101 lines (83 loc) · 2.2 KB
/
token_request.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env bash
# Team Pivot!
# Simple script to test the Oauth Proxy.
# Variables
export REDIRECT_URI="https://app/after-auth"
pass=1
curl_body=$(mktemp)
curl_status=$(mktemp)
# Helper Functions
track_result() {
if [[ "$?" -gt 0 ]]
then
pass=0
fi
}
# --------
# Code and Token Utilities
do_token() {
payload="$1"
curl -X POST \
-s \
-i \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-o "$curl_body" \
-d "$payload" \
"$HOST/TOKEN?redirect_uri=$REDIRECT_URI" > "$curl_status"
if [[ "$(cat "$curl_status")" == "200" ]] && [ "$(cat "$curl_body" | jq ".error")" = "null" ];
then
TOKEN="$(cat "$curl_body")"
fi
}
assign_code() {
local network=""
if [[ $HOST == *"localhost"* ]];
then
network="-it --network container:oauth-proxy_oauth-proxy_1"
else
network=""
fi
local code
code=$(docker run \
$network \
vasdvp/lighthouse-auth-utils:1.1.2 auth \
--redirect-uri="$REDIRECT_URI" \
--authorization-url="$HOST" \
--user-email="$USER_EMAIL" \
--user-password="$USER_PASSWORD" \
--client-id="$CLIENT_ID" \
--client-secret="$CLIENT_SECRET" \
--grant_consent="false" \
--scope="openid profile offline_access email address phone launch/patient" \
--code-only)
local CODE
CODE=$(echo "$code" | jq ".code" | tr -d '"')
if [[ -z $CODE ]];
then
echo -e "\nFailed to retrieve code."
echo "This is likely a lighthouse-auth-utilities bot issue."
echo "Check for valid configuration."
echo "Exiting ... "
exit 1
fi
echo "$CODE"
}
# Pulling latest lighthouse-auth-utils docker image if necessary
docker pull vasdvp/lighthouse-auth-utils:1.1.2
echo "Fetching code ..."
CODE=$(assign_code)
echo "Retrieved Code ${CODE}"
echo "Fetching Token"
do_token "$(jq \
-scn \
--arg client_id "$CLIENT_ID" \
--arg grant_type "authorization_code" \
--arg code "$CODE" \
--arg secret "$CLIENT_SECRET" \
'{"client_id": $client_id, "grant_type": $grant_type, "code": $code, "client_secret": $secret}')"
echo ""
cat $curl_status
echo ""
cat $curl_body
echo ""