This repository has been archived by the owner on Mar 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurltest
executable file
·66 lines (59 loc) · 2.06 KB
/
curltest
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
#!/bin/bash -v
##########
#
# functions
#
##########
function die {
echo $@
exit 1
}
RESPONSE_CODE=
REDIRECT_LOCATION=
function PARSE {
RESPONSE_CODE=`cat tmp | grep '^HTTP/1.1' | cut -f2 -d' '`
[ "$RESPONSE_CODE" = "" ] && die "no response code"
if [ "$RESPONSE_CODE" = "307" ]
then
REDIRECT_LOCATION=`cat tmp | grep '^Location: ' | sed 's,^Location: ,,' | tr -d '[:cntrl:]'`
else
REDIRECT_LOCATION=
fi
}
##########
#
# data
#
##########
user=guest
pass=1234
clientId=CLIENT_ID
clientSecret=CLIENT_SECRET
# --------- access the protected resource:
curl -i "http://localhost:8080/protected/data" > tmp
PARSE
echo $RESPONSE_CODE
#[ "$RESPONSE_CODE" = "307" ] || die "should have been redirected. $RESPONSE_CODE"
echo $REDIRECT_LOCATION
#[ "`echo $REDIRECT_LOCATION | grep ^http://localhost:8080/authorize`" = "" ] && die "redirected to unexpected location: $REDIRECT_LOCATION"
# ---- log on:
#FIXME: should be using digest auth
#curl -i --basic --user ${user}:${pass} "http://localhost:8080/oauth/authorize?client_id=${clientId}&client_secret=${clientSecret}&redirect_uri=http://localhost:8080/protected/data&scope=AnOAuthScope&response_type=token" > tmp
curl -i --basic --user ${user}:${pass} "http://localhost:8080/oauth/authorize?client_id=${clientId}&client_secret=${clientSecret}&redirect_uri=http:%2F%2Flocalhost%3A8080%2Fprotected%2Fdata&scope=AnOAuthScope&response_type=token" > tmp
cat tmp
PARSE
# verify that we got a 307:
[ "$RESPONSE_CODE" = "307" ] || die "should have been redirected. $RESPONSE_CODE"
# retrieve the access token from the redirect:
token=`echo $REDIRECT_LOCATION | sed 's,^.*=,,' | sed 's,$,,'`
echo $REDIRECT_LOCATION
echo $token
# --------- access the protected resource:
#curl --basic --user ${user}:${pass} -i -L "http://localhost:8080/protected/data?access_token=$token" > tmp
#this is how we pass the access token in the new revision
#curl -i "http://localhost:8080/protected/data?access_token=$token" > tmp
#but we are still using revision 10 for this
curl -i "http://localhost:8080/protected/data?oauth_token=$token" > tmp
cat tmp
PARSE
echo $RESPONSE_CODE