Access token now works. Added html file that is deployed on the server for showing the code.

This commit is contained in:
Michael Taboada 2023-01-29 00:42:10 -08:00
parent a6c8fd9277
commit a8f0d6eee3
2 changed files with 32 additions and 2 deletions

30
ratatoskr-success.html Normal file
View File

@ -0,0 +1,30 @@
<html>
<head>
<title>Ratatoskr success!</title>
</head>
<body>
<h1>Authorized successfully</h1>
<p>
Please copy and paste this code into your waiting Ratatoskr:
</p>
<div id="code-div"><noscript>Sorry, but this webpage requires javascript. As a workaround, you can extract the code parameter from the url.</noscript></div>
<script type="text/javascript">
function getQueryParams(qs) {
qs = qs.split('+').join(' ');
var params = {},
tokens,
re = /[?&]?([^=]+)=([^&]*)/g;
while (tokens = re.exec(qs)) {
params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]);
}
return params;
}
var query = getQueryParams(document.location.search);
document.getElementById("code-div").innerHTML = "<p>" + query.code + "</p>";
</script>
</body>
</html>

View File

@ -17,12 +17,12 @@ get_oauth_token() {
done
redirectURI="file://$(realpath ${0})"
# get client id and secret
curl -s -X POST -d client_name="${softwareName}" -d redirect_uris="://${redirectURI}" "${instanceURL}/api/v1/apps" |
curl -s -X POST -d client_name="${softwareName}" -d "redirect_uris=https://billy.wolfe.casa/ratatoskr-success.html" -d "scopes=read write follow push" -d "website=https://git.stormux.org/storm/ratatoskr" "${instanceURL}/api/v1/apps" |
jq --raw-output '"client_id=\"\(.client_id)\"\nclient_secret=\"\(.client_secret)\""' > "${configPath}/${configFile}"
# Load the new variables from the configuration file
source "${configPath}/${configFile}"
# Create the url to get the oauth token
local url="${instanceURL}/oauth/authorize?client_id=${client_id}&redirect_uri=${redirectURI}&response_type=code&scope=read+write+follow"
local url="${instanceURL}/oauth/authorize?client_id=${client_id}&redirect_uri=https://billy.wolfe.casa/ratatoskr-success.html&response_type=code&scope=read%20write%20follow%20push"
echo "Please open the following url in your browser."
echo "Copy the generated token, and paste it here, then press enter to continue."
echo