From ffd63c98f6456ce85db7b3aa24114cd6421c92e5 Mon Sep 17 00:00:00 2001 From: stormdragon2976 Date: Sat, 28 Jan 2023 14:57:45 -0500 Subject: [PATCH] I was doing the client_id bit completely wrong. This should be much better. --- ratatoskr.sh | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/ratatoskr.sh b/ratatoskr.sh index e69d711..4209e44 100755 --- a/ratatoskr.sh +++ b/ratatoskr.sh @@ -17,28 +17,24 @@ get_oauth_token() { break fi done - # Generate a client id - clientId="$(shuf -en42 -- {a..z} {A..Z} {0..9} - _)" - # Fix the output from shuf so that it is a single string. - clientId="${clientId//[[:space:]]/}" - # Create the redirect uri, basically not needed here, but we need something redirectURI="file://$(realpath ${0})" - # Create the url to get the oauth token - local url="${instanceURL}/oauth/authorize?client_id=${clientId}&redirect_uri=${redirectURI}&response_type=code&scope=read%20write%20follow" - echo "Please open the following url in your browser." - echo "Copy the generated token, and paste it here." - echo - echo "${url}" - echo + # get client id and secret + curl -s -X POST -d client_name="${softwareName}" -d redirect_uris="://${redirectURI}" "${instanceURL}/api/v1/apps" | + jq 'to_entries | .[] | "export \(.key)='\''\(.value)'\''"' > "${configPath}/${configFile}" } # Variable initialization configPath="${XDG_CONFIG_HOME:-$HOME/.config}/ratatoskr" # Path for settings, usually ~/.config/ratatoskr -configFile="default.token" # The default token, eventually will support multiple accounts. +configFile="default.conf" # The default config file, eventually will support multiple accounts. softwareName="Ratatoskr" # The name of the client. # Main code starts here + +# make sure the configuration path exists: +mkdir -p "${configPath}" + get_oauth_token + exit 0