-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathonedrive-authorize
executable file
·21 lines (19 loc) · 1.2 KB
/
onedrive-authorize
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
script_base_folder=$(dirname "$0")
source "${script_base_folder}/onedrive.cfg"
source "${script_base_folder}/onedrive-base"
export json_parser="${script_base_folder}/libs/json/bash-json-parser"
echo "Please open the following URL in your browser and follow the steps until you see a blank page:"
echo "https://login.live.com/oauth20_authorize.srf?client_id=${api_client_id}&scope=wl.offline_access%20${api_permissions}&response_type=code&redirect_uri=https://login.live.com/oauth20_desktop.srf"
echo ""
echo "When ready, please enter the value of the code parameter (from the URL of the blank page) and press return"
read code
api_json_result=$(curl -s -d "client_id=${api_client_id}&client_secret=${api_client_secret}&code=${code}&grant_type=authorization_code&redirect_uri=https://login.live.com/oauth20_desktop.srf" -X POST "${api_auth_url}")
refresh_token=$(echo "${api_json_result}" | "${json_parser}" | grep -E "^refresh_token=" | cut -d= -f2-)
if [ "${refresh_token}" != "" ]; then
filesystem_save_refresh_token "${refresh_token}"
echo "It seems like we have a refresh token, so we are ready to go"
else
echo "Something went wrong, here is the API response:"
echo "${api_json_result}"
fi