mirror of
https://github.com/natsukagami/youmubot.git
synced 2025-05-23 16:50:49 +00:00
Add script to fetch osu! API token
This commit is contained in:
parent
a4ac2b9e2c
commit
4b1ae32256
1 changed files with 39 additions and 0 deletions
39
scripts/get_osu_api_token.fish
Normal file
39
scripts/get_osu_api_token.fish
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
if test -z $OSU_API_CLIENT_ID || test -z $OSU_API_CLIENT_SECRET
|
||||||
|
echo "You need to set OSU_API_CLIENT_ID and OSU_API_CLIENT_SECRET"
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if set -q OSU_API_TOKEN
|
||||||
|
echo "OSU_API_TOKEN already set. Unset it to re-request the token"
|
||||||
|
echo "set --erase OSU_API_TOKEN"
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
|
echo "Requesting token from osu! API..."
|
||||||
|
|
||||||
|
set TOKEN_JSON (curl --request POST \
|
||||||
|
"https://osu.ppy.sh/oauth/token" \
|
||||||
|
--header "Accept: application/json" \
|
||||||
|
--header "Content-Type: application/x-www-form-urlencoded" \
|
||||||
|
--fail-with-body \
|
||||||
|
--silent \
|
||||||
|
--data "client_id=$OSU_API_CLIENT_ID&client_secret=$OSU_API_CLIENT_SECRET&grant_type=client_credentials&scope=public")
|
||||||
|
|
||||||
|
if test $status -ne 0
|
||||||
|
echo "Error while trying to request osu! API token:"
|
||||||
|
echo $TOKEN_JSON
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
|
set OSU_API_TOKEN (echo $TOKEN_JSON | jq -r ".access_token")
|
||||||
|
if test $status -ne 0
|
||||||
|
echo "Error while trying to request osu! API token:"
|
||||||
|
echo $TOKEN_JSON
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
|
alias curl-osu='curl --header "Authorization: Bearer $OSU_API_TOKEN" \
|
||||||
|
--header "Content-Type: application/json" \
|
||||||
|
--header "Accept: application/json"'
|
||||||
|
|
||||||
|
echo "OSU_API_TOKEN set. Use `curl-osu` for a `curl` wrapper with the token already loaded."
|
Loading…
Add table
Add a link
Reference in a new issue