forked from membrane/api-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.sh
More file actions
executable file
·36 lines (31 loc) · 806 Bytes
/
client.sh
File metadata and controls
executable file
·36 lines (31 loc) · 806 Bytes
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
clientId="abc"
clientSecret="def"
tokenEndpoint="http://localhost:7007/oauth2/token"
target="http://localhost:2000"
username=$1
password=$2
parseResponse(){
IFS='"' read -ra ADDR <<< "$1"
echo "Got Token: ${ADDR[3]}"
authHeader="Authorization: ${ADDR[7]} ${ADDR[3]}"
}
getToken(){
body="grant_type=password&username=${username}&password=${password}&client_id=${clientId}&client_secret=${clientSecret}"
echo "1.) Requesting Token"
echo "POST $tokenEndpoint"
echo $body
echo
call=$(curl -s -d $body $tokenEndpoint)
parseResponse $call
}
sendRequestToTarget(){
echo
echo "2.) Calling API"
echo "GET $target"
echo "$authHeader"
targetResult=$(curl -s -H "$authHeader" $target)
echo
echo Got: $targetResult
}
getToken
sendRequestToTarget