gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

auth_flow.sh (1828B)


      1 #!/bin/sh
      2 
      3 set -eux
      4 
      5 SERVER_URL="http://localhost:8080"
      6 REDIRECT_URI="${SERVER_URL}"
      7 CLIENT_NAME="Test Application Name"
      8 REGISTRATION_REASON="Testing whether or not this dang diggity thing works!"
      9 REGISTRATION_USERNAME="${1}"
     10 REGISTRATION_EMAIL="${2}"
     11 REGISTRATION_PASSWORD="very safe password 123"
     12 REGISTRATION_AGREEMENT="true"
     13 REGISTRATION_LOCALE="en"
     14 
     15 # Step 1: create the app to register the new account
     16 CREATE_APP_RESPONSE=$(curl --fail -s -X POST -F "client_name=${CLIENT_NAME}" -F "redirect_uris=${REDIRECT_URI}" "${SERVER_URL}/api/v1/apps")
     17 CLIENT_ID=$(echo "${CREATE_APP_RESPONSE}" | jq -r .client_id)
     18 CLIENT_SECRET=$(echo "${CREATE_APP_RESPONSE}" | jq -r .client_secret)
     19 echo "Obtained client_id: ${CLIENT_ID} and client_secret: ${CLIENT_SECRET}"
     20 
     21 # Step 2: obtain a code for that app
     22 APP_CODE_RESPONSE=$(curl --fail -s -X POST -F "scope=read" -F "grant_type=client_credentials" -F "client_id=${CLIENT_ID}" -F "client_secret=${CLIENT_SECRET}" -F "redirect_uri=${REDIRECT_URI}" "${SERVER_URL}/oauth/token")
     23 APP_ACCESS_TOKEN=$(echo "${APP_CODE_RESPONSE}" | jq -r .access_token)
     24 echo "Obtained app access token: ${APP_ACCESS_TOKEN}"
     25 
     26 # Step 3: use the code to register a new account
     27 ACCOUNT_REGISTER_RESPONSE=$(curl --fail -s -H "Authorization: Bearer ${APP_ACCESS_TOKEN}" -F "reason=${REGISTRATION_REASON}" -F "email=${REGISTRATION_EMAIL}" -F "username=${REGISTRATION_USERNAME}" -F "password=${REGISTRATION_PASSWORD}" -F "agreement=${REGISTRATION_AGREEMENT}" -F "locale=${REGISTRATION_LOCALE}" "${SERVER_URL}/api/v1/accounts")
     28 USER_ACCESS_TOKEN=$(echo "${ACCOUNT_REGISTER_RESPONSE}" | jq -r .access_token)
     29 echo "Obtained user access token: ${USER_ACCESS_TOKEN}"
     30 
     31 # # Step 4: verify the returned access token
     32 curl -s -H "Authorization: Bearer ${USER_ACCESS_TOKEN}" "${SERVER_URL}/api/v1/accounts/verify_credentials" | jq