Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- oauth_codeURL="https://bfw.thecopia.com/rest/api/oauth2/authorize?client_id=d3efbc43-2594-11e6-aa00-000d3a00d1a8&response_type=code&redirect_uri=https%3A%2F%2Freader.thecopia.com%2Fauth%2Fbfw%2Fcallback&scope=user_details&state=0e0165d2b9e9d3b7812a114e95f940efbcef813c45ab0719"
- bookURL="http://reader.thecopia.com/books/2485888?uid=bf0c433e-b799-11e6-8521-000d3a00d1a8&tid=8"
- basic_auth_header='ZDNlZmJj****************************4Omo4WWhjM00='
- # As there is no URL escape module for Bash
- # and curl's --data-urlencode acts wrong way
- # please replace special symbols with URL encoded.
- # Full list: http://www.obkb.com/dcljr/charstxt.html
- username=m*************r
- password=*******
- authURL="https://${username}:${password}@bfw.thecopia.com/rest/api/"
- cookieJarFile=cookies.txt
- # Clause 1: get cookies
- curl --silent \
- --output /dev/null \
- --location-trusted \
- --request GET \
- --cookie-jar ${cookieJarFile} \
- ${authURL}
- # Clause 2: get OAuth code
- OAUTH_CODE=$(curl --include \
- --silent \
- --request GET \
- --cookie ${cookieJarFile} \
- ${oauth_codeURL} | grep 'Location:' | awk -F '=' {'print $2'} | tr -d '\r'
- )
- # Clause 3: get access token
- tokenURL="https://bfw.thecopia.com/rest/api/oauth2/token?code=${OAUTH_CODE}&grant_type=authorization_code&redirect_uri=https%3A%2F%2Freader.thecopia.com%2Fauth%2Fbfw%2Fcallback&response_type=authorization_code"
- token=$(curl --silent \
- --request POST \
- --header "Authorization: Basic ${basic_auth_header}" \
- --header "Content-Type: application/x-www-form-urlencoded" \
- --cookie ${cookieJarFile} \
- ${tokenURL} | jq '.access_token' | tr -d '"'
- )
- # Clause 4: fetch book
- #HTTP_RESP_CODE=$(
- curl --head \
- --silent \
- --location-trusted \
- --data "oauth_token=${token}" \
- --cookie ${cookieJarFile} \
- ${bookURL}
- #)
- # Remove security sensitive file
- rm --force ${cookieJarFile}
- #if [ ${HTTP_RESP_CODE} -eq "200" ]
- #then
- # echo "OK- ${HTTP_RESP_CODE}"
- # exit 0
- #else
- # echo "CRITICAL- ${HTTP_RESP_CODE}"
- # exit 2
- #fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement