Advertisement
singaporian

Untitled

Dec 27th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.15 KB | None | 0 0
  1. 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"
  2.  
  3. bookURL="http://reader.thecopia.com/books/2485888?uid=bf0c433e-b799-11e6-8521-000d3a00d1a8&tid=8"
  4.  
  5. basic_auth_header='ZDNlZmJj****************************4Omo4WWhjM00='
  6.  
  7. # As there is no URL escape module for Bash
  8. # and curl's --data-urlencode acts wrong way
  9. # please replace special symbols with URL encoded.
  10. # Full list: http://www.obkb.com/dcljr/charstxt.html
  11. username=m*************r
  12. password=*******
  13.  
  14. authURL="https://${username}:${password}@bfw.thecopia.com/rest/api/"
  15.  
  16. cookieJarFile=cookies.txt
  17.  
  18.  
  19. # Clause 1: get cookies
  20. curl --silent \
  21.      --output /dev/null \
  22.      --location-trusted \
  23.      --request GET \
  24.      --cookie-jar ${cookieJarFile} \
  25.      ${authURL}
  26.  
  27.  
  28. # Clause 2: get OAuth code
  29. OAUTH_CODE=$(curl --include \
  30.                   --silent \
  31.                   --request GET \
  32.                   --cookie ${cookieJarFile} \
  33.                   ${oauth_codeURL} | grep 'Location:' | awk -F '=' {'print $2'} | tr -d '\r'
  34.             )
  35.  
  36.  
  37. # Clause 3: get access token
  38. 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"
  39.  
  40.  
  41. token=$(curl --silent \
  42.      --request POST \
  43.      --header "Authorization: Basic ${basic_auth_header}" \
  44.      --header "Content-Type: application/x-www-form-urlencoded" \
  45.      --cookie ${cookieJarFile} \
  46.      ${tokenURL} | jq '.access_token' | tr -d '"'
  47.      )
  48.  
  49.  
  50. # Clause 4: fetch book
  51. #HTTP_RESP_CODE=$(
  52. curl --head \
  53.      --silent \
  54.      --location-trusted \
  55.      --data "oauth_token=${token}" \
  56.      --cookie ${cookieJarFile} \
  57.      ${bookURL}
  58. #)
  59.  
  60.  
  61.  
  62. # Remove security sensitive file
  63. rm --force ${cookieJarFile}
  64.  
  65. #if [ ${HTTP_RESP_CODE} -eq "200" ]
  66. #then
  67. #    echo "OK- ${HTTP_RESP_CODE}"
  68. #    exit 0
  69. #else
  70. #    echo "CRITICAL- ${HTTP_RESP_CODE}"
  71. #    exit 2
  72. #fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement